Three-Valued Logic and UNKNOWN
Why NULL = NULL is not true and how UNKNOWN propagates through conditions.
Why NULL Trips Up Candidates
NULL is the number one source of wrong answers in SQL interviews. The trap is treating it like a normal value, when in reality NULL means 'unknown' or 'missing', not zero and not an empty string.
Interviewers love this because the syntax looks correct but the result is silently wrong. They might show you a filter that 'should' return a row and ask why it returns nothing.
In this lesson you will build the mental model that defuses every NULL question: three-valued logic. Once you internalize that comparisons can return TRUE, FALSE, or UNKNOWN, the rest follows.
NULL Is Not a Value
The single most important sentence to say in an interview: NULL is the absence of a value, not a value itself.
That means you cannot compare it with = the way you compare numbers. The database has no idea whether two unknowns are equal, so it refuses to commit to TRUE or FALSE.
NULL = 5is not FALSE, it is UNKNOWNNULL = NULLis not TRUE, it is UNKNOWNNULL <> NULLis also UNKNOWN
This is why a naive equality filter on a nullable column quietly drops rows.
All lessons in this course
- Three-Valued Logic and UNKNOWN
- IS NULL, IS NOT NULL and NULL-Safe Equality
- COALESCE, NULLIF and ISNULL
- NULLs in Aggregates, Joins and DISTINCT