Чем заменять not in (select ... ) в запросах ? например select from table1 where id not in (select id from table2)
1) используй алиасы - так больше шансов что не пойдет вложенный запрос в цикле. 2) left join t2 on t1.id=t2.id where t2.id is null