SQL Case File: 006
Case Closed
NULL Behavior| Base Component | Unknown value |
|---|---|
| Answer Space | Rows whose predicates evaluate to UNKNOWN do not pass WHERE; NULL-aware logic is required. |
| Problem Space | Relevant data, constraints, relationships, ordering, NULLs, duplicates, and scale. |
| Decision Space | Choose the operation that lawfully transforms evidence into the answer. |
| SQL Reasoning Engine | Use the engine to ask whether NULLs are part of the problem before trusting equality, NOT IN, or nullable filters. |
| SQL Pattern | UNKNOWN is not TRUE; predicates must account for NULL explicitly. |
| Common Trap | Column = NULL and NOT IN against nullable subquery values. |
| Hands-On Lab | Build a truth table and compare NOT IN with NOT EXISTS. |
| Interview Principle | Explain the result, then the query, then the likely SQL Server work. |
If you remember only one thing from this Case File: before writing SQL, ask what data is needed, how to filter it, whether the columns are indexed, whether the predicate is sargable, and how much work SQL Server has to do.