> SELECT * FROM table1 LEFT JOIN table2 on table1.field=table2.field > WHERE table2.field is NULL > > So far, so good, I get the records I want. Then in the callback, I try > > INSERT INTO table1 etc...
I'm not sure I understand your logic. Your left join indicates that there are records missing from table2, so I would expect that you want to insert the missing records into table2. Assuming that's what you meant, insert into table2 select * from table1 where table1.field not in (select field from table2) or insert into table2 select * from table1 where not exists (select field from table2 where table2.field=table1.field) The subquery in the first form is static (executed only once). The subquery in the second form is correlated (executed many times), but the second form can be faster in some circumstances. Regards