Comparisons with null
- When we use single equal to compare anything with
NULL
, we get anotherNULL
. That’s even true when comparingNULL
to itself. - SQL also has
IS NULL
andIS NOT NULL
comparisons that properly check forNULL
values.
SELECT 5 IS NOT NULL AS result;
--Result:
[{result: 1}]
- Usually, you’ll see
IS NULL
andIS NOT NULL
as conditions inWHERE
queries.
SELECT * FROM users WHERE email IS NOT NULL