I have a simple SQL query which lists all the records that are not in a second table. select first.id from first where first.id not in (select id from second); As the second table is very huge, it takes a very long to process the query. Is there a way to rewrite the query to run it quicker?