I need to find all id's from the OldTable that doesn't exist in the NewTable
Why won't this query find the id?
SELECT old_id FROM OldTable WHERE old_id NOT IN (
SELECT id FROM NewTable)
By them selves they return this
--Returns the id 18571
SELECT old_id FROM OldTable WHERE old_id = 18571
--Returns nothing
SELECT id FROM NewTable WHERE id = 18571
Am I missing something obvious here?
Both columns are of type int
and primary keys.
SOLVED
The id column had null's in them, I was just being ignorant =/
These works:
SELECT old_id FROM OldTable EXCEPT SELECT id FROM NewTable
SELECT * FROM old_table ot WHERE NOT EXISTS (
SELECT * FROM new_table nt WHERE nt.id = ot.old_id)
These doesn't work:
SELECT old_id FROM OldTable LEFT JOIN NewTable ON old_id = id WHERE id IS NULL
SELECT old_id FROM OldTable WHERE old_id NOT IN (
SELECT id FROM NewTable)