A subquery used with NOT IN returns a NULL among its values. What happens to the outer query's result?
Correct answer
D. It returns no rows at all, because every comparison with NULL yields unknown
16 views
D. It returns no rows at all, because every comparison with NULL yields unknown
16 views
Three-valued logic makes x NOT IN (1, 2, NULL) equivalent to x <> 1 AND x <> 2 AND x <> NULL, and that last term is unknown for every x, so the filter never passes. NOT EXISTS is immune because it tests row presence rather than value equality. Add WHERE col IS NOT NULL inside the subquery, or switch to NOT EXISTS, to keep the intended semantics.
Asked in: NTS, PPSC IT, Interviews
Not sure why the answer is D? Ask here and get an explanation.