NULL in SQL represents the absence of a value, not zero or an empty string. It propagates through arithmetic and comparisons in ways that surprise developers coming from Python or JavaScript. Any arithmetic involving NULL produces NULL. Any comparison using = or != against NULL returns UNKNOWN, not TRUE or FALSE.
Use IS NULL and IS NOT NULL to test for missing values, never = NULL.
COUNT(*) counts all rows including NULLs; COUNT(column) skips NULLs in that column.
COALESCE returns the first non-NULL value in its argument list and is the standard way to substitute a default.
NULL values sort last in ascending order in PostgreSQL; behavior varies by database engine.
Two rows with NULL in the join column will not match each other, which removes them from INNER JOINs.
Visit PyCodeIt
Top comments (0)