IS NULL and IS NOT NULL
NULL is checked with dedicated predicates
We already know that NULL represents the absence of a known value. That is why it cannot be correctly searched as an ordinary value with = or <>.
SELECT id, name
FROM users
WHERE email IS NULL;
IS NULL returns rows where the value is missing. The opposite check is written as IS NOT NULL.
SELECT id, name
FROM users
WHERE email IS NOT NULL;
Why = NULL does not behave as expected
A comparison assumes two known values. If one side is unknown, SQL cannot say that they are equal or not equal in the ordinary way. That is why email = NULL is not a substitute for email IS NULL.
Remember the pair: IS NULL / IS NOT NULL.
This is not a stylistic preference; it is SQL's dedicated semantics for testing a missing value.
Check yourself
Exercise review
The mentor knows the solution and will help you reach it independently
Sign in to use the Mentor
The Mentor uses the current exercise and your conversation history.
Sign in
Review the key nuances and the answer after making your own attempt.
Sign in to view the solution
The solution and explanation are available after signing in.
Sign in