SQL NULL Explained: Why = NULL Fails (Use IS NULL)
NULL means unknown, so = NULL never matches. Use IS NULL / IS NOT NULL — with COUNT quirks and join pitfalls.
NULL is not a value
In SQL, NULL means “unknown / missing.” It is not 0, not '', and not “false.”
-- Wrong — never keeps NULL rows WHERE status = NULL -- Right WHERE status IS NULL WHERE status IS NOT NULL
Even NULL = NULL is not true — so two missing values never “match” with =.
-- Example: find orders with a missing status SELECT order_id, status FROM orders WHERE status IS NULL;
Where NULLs bite you
- Filters — always
IS NULL, never= NULL. - LEFT JOIN — unmatched right columns are NULL; a WHERE on them deletes those rows.
- COUNT(column) — skips NULLs;
COUNT(*)counts every row. Details: COUNT(*) vs COUNT(column). - NOT IN (subquery) — a NULL inside the list can make the whole predicate fail unexpectedly.
Coalesce when you need a stand-in
SELECT COALESCE(status, 'unknown') AS status_label FROM orders;
Use COALESCE for display/defaults — not as a substitute for understanding IS NULL.
FAQ
Why doesn’t WHERE column = NULL work?
NULL means unknown. Comparing unknown with = returns unknown, not true, so WHERE drops the row. Use IS NULL.
Is NULL the same as 0 or an empty string?
No. 0 and '' are values. NULL is the absence of a value.
Try it yourself
The fastest way to lock this in is a short drill on the same Northstar Market tables.