NULL in SQL: what it means and how to handle it
NULL means "unknown" or "missing", not zero and not empty text. Any comparison with NULL is unknown, so = NULL never matches. Use IS NULL and IS NOT NULL.
How do you find missing values?
SELECT * FROM customersWHERE phone IS NULL;
WHERE phone = NULL returns nothing, even when phones are missing.
How do aggregates treat NULL?
| Function | NULLs |
|---|---|
COUNT(*) | counted, it counts rows |
COUNT(phone) | ignored |
SUM, AVG, MIN, MAX | ignored |
That's why AVG(bonus) can be higher than you expect: rows without a bonus don't count as zero.
How do you replace NULL with a value?
SELECT name, COALESCE(phone, 'no phone') AS phoneFROM customers;
COALESCE returns the first value that isn't NULL. To count missing bonuses as zero: AVG(COALESCE(bonus, 0)).
Where do NULLs come from in results?
Mostly from LEFT JOIN, for rows without a match. Filtering those columns in WHERE removes the rows again.
Try it yourself. Practise this in a real database in your browser, with instant feedback.
Practise NULL values
Practise NULL values
Updated November 2026.