Why is NOT IN dangerous with NULLs?
Model answer
If the subquery returns even one NULL, x NOT IN (...) evaluates to unknown for every row, so you get no results. Use NOT EXISTS, or filter out NULLs in the subquery.
Learn this topic
Subqueries, EXISTS and CTEs: Queries Inside Queries in the course SQL for Beginners: Learn Databases Step by Step.
Sign in to add your own answer.