The IS NULL
condition is used to select rows if the specified field is NULL. For example,
SELECT *
FROM Employee
WHERE email IS NULL;
Here, the SQL command selects employees who do not have email.

Note: Empty values are considered NULL
. However, 0, ''
and spaces are not considered NULL
.
IS NOT NULL
In SQL, IS NOT NULL
condition is used to select rows if the specified field is NOT NULL. For example,
SELECT *
FROM Employee
WHERE email IS NOT NULL;
Here, the SQL command selects employees who have emails.

IS NULL With COUNT()
We can use the COUNT() function with IS NULL
to count the number of rows with an empty field. For example,
SELECT COUNT(*)
FROM Employee
WHERE email IS NULL;
Here, the SQL command returns the total number of employees that do not have email.

Similarly, we can use the COUNT()
function with IS NOT NULL
to count the number of non-empty fields.