CodeOath
← All posts
SQL70 min total · 18 parts

SQL Fundamentals: Joins, NULL, Aggregate Functions, and Subqueries

Contents — Part 5 of 18: NULL Is Not Zero, Not Empty String, and Not False
Part 5 of 18 · ~1 min

NULL Is Not Zero, Not Empty String, and Not False

This single idea explains most NULL-related surprises: NULL represents an unknown or missing value — not zero, not an empty string, not boolean false. It's a placeholder meaning "there is no value here to compare," and that has real consequences for how comparisons behave.

SELECT * FROM Employees WHERE salary = NULL;   -- returns ZERO rows, always, for every row in the table
SELECT * FROM Employees WHERE salary IS NULL;  -- correctly returns Dave
SELECT * FROM Employees WHERE salary IS NOT NULL; -- everyone except Dave

salary = NULL doesn't mean "salary is unset" — it asks "is salary equal to this unknown value," and the honest answer to that question is always "unknown," never "yes." SQL has no way to spell "compare to NULL and get true" using =; IS NULL / IS NOT NULL are dedicated operators that exist precisely because equality can't do this job.