I spent some time trying to figure out why this query isn’t pulling the results i expected:
SELECT * FROM NGS WHERE ESPSSN NOT IN (SELECT SSN FROM CENSUS)
finally i tried writing the query another way and this ended up getting the expected results:
SELECT * FROM NGS n WHERE NOT EXISTS (SELECT * FROM CENSUS WHERE SSN = n.ESPSSN)
The first query seems more appropriate and “correct”. I use “in” and “not in” all the time for similar selects and have never had a problem that i know of.
If you write out the syntactic sugar,
x not in (1,2,3)becomes:So if the
ssncolumn contains a null value, the first query is the equivalent of:The result of the comparison with NULL is unknown, so the query would not return anything.