intermediateSubqueries, EXISTS & Correlated Subqueries

A query using NOT IN is returning zero rows even though you expect some results. What's the likely cause?

If the subquery in NOT IN returns ANY NULL value, NOT IN returns empty result. Reason: SQL evaluates 'column NOT IN (1, 2, NULL)' as 'column != 1 AND column != 2 AND column != NULL'. The last condition (column != NULL) evaluates to NULL (UNKNOWN), which causes the entire WHERE condition to fail for every row. Fix: 1) Filter NULLs in the subquery: NOT IN (SELECT dept_id FROM employees WHERE dept_id

This is a Pro chapter

Sign in, then upgrade to Pro or Power to unlock this and the full Databases Mastery library.

A query using NOT IN is returning zero rows even though you expect some results. What's the likely cause?

Next Step

Continue to What is the difference between a clustered and non-clustered index?← Back to all SQL questions