SQL IS NULL and IS NOT NULL

In this tutorial, we'll learn about the SQL IS NULL and NOT NULL with the help of examples.

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.

How to use IS NULL in SQL
Example: IS NULL in SQL

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.

How to use IS NOT NULL in SQL
Example: IS NOT NULL in SQL

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.

How to use IS NULL with COUNT() in SQL
Example: IS NULL with COUNT() in SQL

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

Did you find this article helpful?