Back to Developer Roadmap

Not In Null Issues

src/data/question-groups/sql-queries/content/not-in-null-issues.md

4.0788 B
Original Source

Since NULL is unknown, a NOT IN query containing a NULL or NULL in the list of possible values will always return 0 records because of the unknown result introduced by the NULL value. SQL cannot determine for sure whether the value is not in that list.

Let's illustrate this using a table Sales that looks like this:

iddayamount
1Monday200
2Tuesday300
3Wednesday600
4Thursday390
5Friday900
6Saturday600

If you run the query below, it will return an empty result because SQL cannot determine if the value is not in the list because nothing equals or doesn't equal NULL.

sql
SELECT * from sales
WHERE amount NOT IN (200, 300, 600, NULL);