SQL IS NULL
NULL means a value is missing or unknown. It is not zero and not an empty string. Any comparison with NULL, even NULL = NULL, returns unknown, so the row is filtered out.
To find missing values, use IS NULL. To find present values, use IS NOT NULL.
Syntax
WHERE column IS NULL WHERE column IS NOT NULL
Try it yourself
Run the example below on a real PostgreSQL database, then change it and run it again. Nothing to install, no sign-up.
is-null.sql · PostgreSQL
Loading editor…
Examples
1. Find missing values
SELECT id, first_name FROM customers WHERE email IS NULL;
Customers without an email.
2. Find present values
SELECT first_name, last_name FROM employees WHERE department_id IS NOT NULL;
Employees assigned to a department.
Common mistakes
- Writing
= NULLor<> NULL. Both always return no rows. - Forgetting that COUNT(column) skips NULLs while COUNT(*) does not.
Practice: test yourself
This challenge is from our interactive course. Write the query and press Check answer.
Challenge · 20 pts
Return id, first_name and last_name of customers who have no email address.
challenge.sql · PostgreSQL
Loading editor…
FAQ
How do I replace NULL with a value?
Use COALESCE(column, 'fallback'). It returns the first non-NULL argument.
Learn SQL step by step
65 hands-on exercises, streaks, a leaderboard and a certificate.