NULL means “unknown / absent”, and it is never equal to anything — not even another NULL. So WHERE bonus = NULL matches nothing and WHERE bonus != NULL silently drops rows. The only correct tests are IS NULL (keep missing) and IS NOT NULL (keep filled). Functions like COALESCE(bonus, 0) substitute a default for display or math.
--how it works
1
NULL means unknown
Not zero, not empty string — the absence of a value. Three employees have no bonus recorded; that is information, not corruption.
2
NULL is never equal to anything
= NULL and != NULL both evaluate to UNKNOWN, even NULL = NULL. WHERE keeps TRUE only — so both tests match nothing.
3
Use IS NULL / IS NOT NULL
The only correct tests: WHERE bonus IS NULL or WHERE bonus IS NOT NULL.
4
Substitute for display: COALESCE
COALESCE(bonus, 0) renders missing bonuses as 0 without changing stored data.
5
Aggregates skip NULLs
COUNT(*) = 6 but COUNT(bonus) = 3 — NULLs are ignored by COUNT(col), SUM, AVG, MIN, MAX.
--visualization
COUNT(*) counts all rows · COUNT(bonus) skips NULLs
matches predicate filtered out NULL cells
Stage 1 / 8
bonus can be NULL (unknown). WHERE bonus IS NULL — remember: = NULL and != NULL match NOTHING.
--example
query.sql
1SELECTname,bonus
2FROMemployees
3WHEREbonusISNULL;
Result
name
bonus
Bob
NULL
Cynthia
NULL
Farid
NULL
Three employees have no bonus recorded. Flip the toggle to IS NOT NULL and the opposite trio appears — Alice, David and Elena.
--variants
IS NULL
Find the missing values.
query.sql
1SELECTname,bonusFROMemployees
2WHEREbonusISNULL;
Result
name
bonus
Bob
NULL
Cynthia
NULL
Farid
NULL
1Three rows have no bonus recorded.
2bonus = NULL would have returned nothing — the classic bug.
3NULL prints literally in the result table.
IS NOT NULL
Find the filled values.
query.sql
1SELECTname,bonusFROMemployees
2WHEREbonusISNOTNULL
3ORDERBYbonusDESC;
Result
name
bonus
Alice
5000
David
3000
Elena
2500
1The complement of IS NULL — three employees with bonuses.
2ORDER BY sorts them high to low.
3NULL rows never leak into either side by accident.
COALESCE default
Print a stand-in for NULL.
query.sql
1SELECTname,COALESCE(bonus,0)ASbonus_or_zero
2FROMemployees;
Result
name
bonus_or_zero
Alice
5000
Bob
0
Cynthia
0
David
3000
Elena
2500
Farid
0
1COALESCE returns its first non-NULL argument.
2Filled bonuses pass through; missing ones become 0 in the output.
3The stored table is unchanged — this is display-layer only.
COUNT(*) vs COUNT(col)
Aggregates ignore NULLs.
query.sql
1SELECTCOUNT(*)ASall_rows,
2COUNT(bonus)ASwith_bonus
3FROMemployees;
Result
all_rows
with_bonus
6
3
1COUNT(*) counts rows: 6.
2COUNT(bonus) counts non-NULL bonuses: 3.
3AVG(bonus) divides by 3, not 6 — NULLs never dilute averages.
--key facts
Three-valued logicTRUE / FALSE / UNKNOWN — WHERE keeps TRUE only
Count differenceCOUNT(*) = 6 but COUNT(bonus) = 3 on our table
DefaultsCOALESCE(bonus, 0) renders missing bonuses as 0
--use cases
Optional fields: bonus, middle_name, deleted_at — everywhere data is genuinely absent
Reports: COALESCE defaults so tables show 0 instead of blanks
Data-quality checks: WHERE email IS NULL OR email = ''
Soft deletes: WHERE deleted_at IS NULL = "not deleted"
--under the hood
NULL needs an extra bit per row to mark presence — some engines hide it in a null bitmap.
Indexes typically skip NULL entries (or include them, engine-specific) — know your engine before relying on IS NULL lookups.
Practice SQL interview questions
Every SQL lesson maps to the matching interview topic, with answers written for current SQL engines.
Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses →Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free →Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books →