Why does NULL require special handling in SQL queries and tests?
Answer
NULL represents an unknown or absent value, so ordinary comparisons with it usually produce UNKNOWN rather than TRUE or FALSE. Use IS NULL or IS NOT NULL instead of equals, and remember that NULL affects joins, aggregates, NOT IN, sorting and uniqueness differently across database products. Test missing values explicitly at input, storage, query, calculation, export and UI boundaries because silent null handling can change both row counts and business totals.
Strong answer includes
- understands SQL three-valued logic
- uses IS NULL rather than equality
- covers joins, aggregates and end-to-end null propagation
Practical example
Runs against the resettable SQLite sample database used by the playground.
Run the query to see the result.
NULL is not an ordinary value, so equality does not test for absence. NOT EXISTS is also preferable to NOT IN when the subquery can contain NULL because three-valued logic can otherwise make every comparison UNKNOWN.
Expected result: IS NULL returns missing phones; the NOT EXISTS query returns customers without matching orders.