Loading lesson...
TRUE, FALSE, and NULL walk into a bar
TRUE, FALSE, and NULL walk into a bar
Topics covered: NULLs in window functions, NULLs in UNION operations, DISTINCT and NULL, NULL propagation, Three-valued logic (NOT IN)
Sorting and Ordering NULLS FIRST/LAST NULL in PARTITION BY Calculations and Navigation Window Aggregates + NULL LAG/LEAD with NULL
UNION Behavior UNION Deduplication UNION ALL Duplicates
DISTINCT Grouping Behavior NULL Collapsing Context Comparison NULL Behavior by Context
Basic Propagation Rules Arithmetic Propagation String Concatenation Control Flow Propagation CASE Propagation Function Propagation
SQL uses three-valued logic (TRUE, FALSE, UNKNOWN) instead of classical boolean logic. This fundamentally changes how compound conditions behave and breaks some intuitive rules. Three-Valued Logic Boolean operations in SQL don't just have TRUE and FALSE outcomes; UNKNOWN is a third possibility that propagates through logical operators. Truth Tables with UNKNOWN Common Pitfalls Three-valued logic creates counterintuitive behaviors that cause subtle bugs even for experienced developers. The NOT IN