I have a table A that got a field called id that is the primary key of this table. I also have a table called B which also have a field called id as primary key.
Now I want to get all rows from Table A where the id value is not present as value in any table B id field-value.
My first query looked like this:
SELECT a.id FROM a WHERE a.id NOT IN (SELECT DISTINCT b.id FROM b)
Then I build a query that looked like this to improve the speed:
SELECT a.id FROM a LEFT JOIN b ON a.id = b.id WHERE b.id IS NULL
Now I got 600k rows in table A and 400k rows in table B and things are getting very slow. Is there any better query to run for this kind of operation or is there perhaps a better way to solve the problem at all? Any hints or pointers?