0PricingLogin
SQL Interview Prep · Lesson

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 = 5 is not FALSE, it is UNKNOWN
  • NULL = NULL is not TRUE, it is UNKNOWN
  • NULL <> NULL is also UNKNOWN

This is why a naive equality filter on a nullable column quietly drops rows.

All lessons in this course

  1. Three-Valued Logic and UNKNOWN
  2. IS NULL, IS NOT NULL and NULL-Safe Equality
  3. COALESCE, NULLIF and ISNULL
  4. NULLs in Aggregates, Joins and DISTINCT
← Back to SQL Interview Prep