In SQL, NULL does not mean zero, and it does not mean an empty string. It means the value is unknown or missing. That one idea explains why WHERE price = NULL returns nothing, why a NOT IN query can silently drop every row, and why your average does not match your hand calculation.
Comparisons with NULL are unknown
SQL uses three-valued logic: a condition can be true, false or unknown. Any ordinary comparison with NULL, including NULL = NULL, is unknown, not true. A WHERE clause keeps only the rows where the condition is true, so unknown rows are dropped. To test for NULL, use the dedicated operators:
SELECT * FROM customers WHERE phone IS NULL;
SELECT * FROM customers WHERE phone IS NOT NULL;
The NOT IN trap
If the list or subquery inside NOT IN contains even one NULL, the condition can never be true, and the query returns no rows at all. This is one of the most common surprising bugs in SQL.
-- Returns nothing if any blocked.customer_id is NULL
SELECT * FROM customers
WHERE id NOT IN (SELECT customer_id FROM blocked);
-- Safer
SELECT * FROM customers c
WHERE NOT EXISTS (
SELECT 1 FROM blocked b WHERE b.customer_id = c.id
);
How aggregates treat NULL
COUNT(*) counts rows, while COUNT(column) counts only rows where that column is not NULL. SUM, AVG, MIN and MAX ignore NULLs. That means an average is taken over the non-NULL values only, so it can differ from a total divided by the row count. Decide whether a missing value should be skipped, treated as zero or investigated, and write that choice into the query.
COALESCE and NULLIF
COALESCE returns the first non-NULL value from its arguments, which is the standard way to supply a default. NULLIF returns NULL when its two arguments are equal, which is handy for avoiding division by zero.
SELECT COALESCE(discount, 0) AS discount FROM orders;
SELECT revenue / NULLIF(orders, 0) AS revenue_per_order FROM daily_stats;
NULL in joins
A join compares keys with equality, so rows whose key is NULL never match each other. A left join also produces NULLs for unmatched rows, and a filter on the right table in the WHERE clause can remove them, as covered in SQL joins explained.
Grouping, sorting and uniqueness
GROUP BY and DISTINCT treat all NULLs as one group, even though NULL does not equal NULL in a comparison. Where NULLs appear when you sort differs between databases, and many support NULLS FIRST or NULLS LAST to make it explicit. Unique constraints also vary: whether a column may hold several NULLs depends on the database, so check the documentation for yours.
NULL is a data quality signal
A sudden rise in NULLs in a column often means something broke upstream. Tracking the share of non-NULL values is the basic completeness check in data quality dimensions. When the same gaps reach a model, the options for dealing with them are in handling missing data.
A habit worth building
When a query returns fewer rows than expected, or a total looks wrong, check for NULLs in the columns you filter, join and aggregate. Putting the NULL handling into a named step, as in SQL CTEs explained, makes the choice visible to the next reader.
A quick checklist
- Do you use
IS NULLandIS NOT NULL, never= NULL? - Do your
NOT INsubqueries guard against NULLs, or useNOT EXISTS? - Do you know whether each aggregate ignores NULLs?
- Do you supply defaults with
COALESCEdeliberately, not by habit? - Did you check your join keys for NULLs?
If you want help finding and fixing silent data problems in a pipeline, see my ETL and ELT engineering service.
FAQ
Why does NULL = NULL return false in SQL?
It returns unknown, not true or false, because NULL means an unknown value and two unknowns cannot be said to be equal. A WHERE clause drops unknown rows, so use IS NULL to test for NULL.
What is the difference between COUNT(*) and COUNT(column)?
COUNT(*) counts all rows. COUNT(column) counts only the rows where that column is not NULL.
Is NULL the same as zero or an empty string?
No. NULL means the value is missing or unknown, while zero and an empty string are actual values.

