SQL
5 min read
BEGINNER
IS NULL
Quick AnswerUse IS NULL to find missing values and IS NOT NULL to find recorded values. Ordinary equality is not a missing-value test.
Core idea
Use IS NULL to find missing values and IS NOT NULL to find recorded values. Ordinary equality is not a missing-value test.
Minimal example
sql
SELECT NULL = NULL, NULL IS NULL, 0 IS NULL;Expected SQLite rows:
text
NULL | 1 | 0How it works
score = NULL evaluates to UNKNOWN even when score is NULL. IS NULL instead evaluates to a definite truth value. A zero score satisfies IS NOT NULL.
Practical example
sql
SELECT id FROM sort_scores WHERE score IS NULL ORDER BY id;Expected SQLite rows:
text
24Common mistake and practice
Replace WHERE score = NULL with WHERE score IS NULL. Run both and explain why the first returns no rows.