NULL Handling
NULL Handling — Understand NULL semantics — comparisons, COALESCE, NULLIF, NULL-safe joins, and common pitfalls. The guide walks through NULL in Comparisons, COALESCE & IFNULL, NULLIF() Function, NULL in Joins, NULL in Aggregates, Common NULL Pitfalls. NULL represents unknown, not missing or empty. Any comparison with NULL using =, <>, >, <, >=, <= yields unknown (not true or false). WHERE clauses filter out rows where the condition evaluates to unknown. Use IS NULL or IS NOT NULL to check for NULL. The only safe equality check is IS NOT DISTINCT FROM (PostgreSQL/SQLite) which treats NULL… COALESCE(value1, value2, ..., default) returns the first non-NULL argument. Use it to provide fallback values: COALESCE(middle_name, '') returns empty string if middle_name is NULL. COALESCE is standard SQL and accepts multiple arguments. IFNULL (MySQL/SQLite) or ISNULL (SQL Server) are two-argument variants. NVL (Oracle) is the equivalent. The guide is organized into 6 sections that build on each other, each pairing a prose explanation with real SQL you can run as-is.