Skip to main content
PProfileMatch
← Path

Advanced SQL · SQL Subqueries, UNION, INTERSECT, EXCEPT and CASE for Reporting

0 XP
  1. 1 current stop: learning
  2. 2 upcoming
  3. 3 upcoming
  4. 4 upcoming
  5. 5 upcoming

Finish after stop 5

Stop 1 of 5 · Clinic waiting room: the missing patient

Trick to keep in mind+3 XP

NOT IN plus one NULL in the list returns no rows. Reach for NOT EXISTS.

x NOT IN (1, NULL) expands to x <> 1 AND x <> NULL, and the second test is unknown for every x, so the whole condition can never be true. The query returns nothing and raises no error. NOT EXISTS with a correlated subquery compares with = on real rows and is unaffected by NULLs.

Read it once, then a question tests whether the trick stuck.