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;
Result on the SQL Café sample data (1 row)
namecity
FayNULL

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;
Result on the SQL Café sample data (8 rows)
namecity
AvaAustin
BenSeattle
CaraDenver
DevAustin
EliSeattle
FayUnknown
GusDenver
HanaAustin

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;
Result on the Acme Co. (company data) sample data (1 row)
employeeswith_department
1514

Common mistakes

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.

Related SQL tutorials