SQL NULL Values
NULL means a value is missing or unknown. It isn’t zero or empty text, and it doesn’t equal anything, not even another NULL. That’s why it needs its own operators.
Updated December 1, 2026
Syntax
WHERE column IS NULL
WHERE column IS NOT NULL
COALESCE(column, fallback)
Find missing values with IS NULL
Fay hasn’t told us her city.
SELECT name, city
FROM customers
WHERE city IS NULL;
| name | city |
|---|---|
| Fay | NULL |
Replace NULL with COALESCE
COALESCE returns its first non-null argument, which is handy for display.
SELECT name, COALESCE(city, 'Unknown') AS city
FROM customers;
| name | city |
|---|---|
| Ava | Austin |
| Ben | Seattle |
| Cara | Denver |
| Dev | Austin |
| Eli | Seattle |
| Fay | Unknown |
| Gus | Denver |
| Hana | Austin |
NULL and COUNT
COUNT(*) counts rows. COUNT(column) skips NULLs. In company data, one contractor has no department.
SELECT COUNT(*) AS employees,
COUNT(department_id) AS with_department
FROM employees;
| employees | with_department |
|---|---|
| 15 | 14 |
Common mistakes
WHERE city = NULLreturns no rows. Always useIS NULL.WHERE city <> 'Austin'also skips NULL cities. AddOR city IS NULLif you want them.- Arithmetic with NULL gives NULL:
price + NULLis NULL. UseCOALESCE(x, 0)when a missing number should count as zero.
Practice NULL Values interactively
Write real queries in your browser and get instant feedback in the lesson “Working with NULL” (Unit 2). New learners can start free from the first lesson.
Frequently asked questions
Is NULL the same as an empty string?
No. '' is a known value with no characters; NULL is unknown. (Oracle is the exception: it stores empty strings as NULL.)
How does ORDER BY sort NULLs?
It depends on the database. SQLite and MySQL put them first when sorting ascending; PostgreSQL puts them last. Many databases support NULLS FIRST or NULLS LAST.