Why = NULL doesn't work
This looks reasonable, but it returns no rows at all:
-- Always returns nothing
SELECT name FROM suppliers WHERE contact_email = NULLA comparison with NULL is never true. "Is an unknown value equal to an unknown value?" The honest
answer is "unknown", so the row isn't kept. That's why SQL has IS NULL.
The trap with "not equal to"
The same rule catches people out with <>. This query is meant to find every customer outside the
North:
SELECT name, region FROM customers WHERE region <> 'North'It skips the customers whose region is NULL, because "is unknown not equal to North?" is also unknown. If you want them too, say so:
SELECT name, region
FROM customers
WHERE region <> 'North' OR region IS NULLWhenever you filter on a column that can be NULL, ask yourself: should the NULL rows be in or out?