Problem Statement
When can NOT IN return zero rows unexpectedly?
Explanation
NOT IN compares each value to the list. If the list contains NULL, comparisons become unknown and no row qualifies.
Use NOT EXISTS for anti-joins, or ensure the subquery column is declared NOT NULL or filtered to exclude NULL.
Code Solution
SolutionRead Only
SELECT a.id FROM A a WHERE a.id NOT IN ( SELECT b.a_id FROM B b WHERE b.a_id IS NOT NULL );
Practice Sets
This question appears in the following practice sets:
