SQL: NULL is not equal to anything, including NULL

NULL means unknown, so any comparison with it is unknown rather than true or false. = NULL never matches; IS NULL is the only test.

Code
SELECT * FROM users WHERE deleted_at = NULL;      -- always 0 rows
SELECT * FROM users WHERE deleted_at IS NULL;     -- correct

SELECT NULL = NULL       AS eq,
       NULL IS NULL      AS is_null,
       NULL <> 'x'       AS neq;
Output
eq     | is_null | neq
NULL   | true    | NULL

-- NULL in a boolean position is treated as "not true", so WHERE discards it.
-- IS DISTINCT FROM compares treating NULLs as equal, when you need that.
Advertisement

Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.

Published 2026-08-25