NULL in SQL: Why = NULL Finds Nothing and What to Write Instead
By Michael Nocito , data analyst · Published August 7, 2026 By the end of this page you can predict what any query does when it meets a missing value, which is the skill that separates "my query returned nothing and I don't know why" from a two-second fix. You will know why = NULL matches zero rows, why one NULL can empty an entire NOT IN , and how NULLs quietly move averages, counts, groups, and…
NULL is a special value in SQL that represents an unknown or missing value. When used in a comparison, such as = NULL, it always returns unknown, which means the row is excluded from the result set. This is why a query like SELECT * FROM tickets WHERE assignee = NULL; returns zero rows, even for tickets with no assignee. To check for NULL values specifically, use the IS NULL operator, like WHERE assignee IS NULL.
This distinction is crucial because NULL does not equal any value, including itself. Understanding this concept helps in predicting query behavior and avoiding unexpected results. For example, the query SELECT COUNT(*) AS n FROM tickets WHERE assignee IS NULL; returns the number of rows with missing assignees, which is the intended result.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.