Name
ISNULL()
Synopsis
ISNULL(column
)
Use this function to determine whether the value of the argument given in parentheses is NULL. It returns 1 if the value is NULL and 0 if it is not NULL. Here is an example:
SELECT CONCAT(name_first, SPACE(1), name_last) AS Client, telephone_work AS 'Work Telephone' FROM clients WHERE ISNULL(telephone_home);
In this example, after realizing that we don’t have home
telephone numbers for several of our clients, we use the
ISNULL()
function in the
WHERE
clause of a SELECT
statement to list client names and their work telephone numbers so
that we can call them to get their home telephone numbers. Only rows
in which the home_telephone
column is NULL will
result in a value of 1 and will therefore be shown in the
results.
Get MySQL in a Nutshell, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.