delete from Table1 where id not in (select id from table2);
1.id已经建立了索引
2.表中数据10w条朝上
如果数据量小的话,此sql语句是可以很快执行的。
有什么好的办法优化此sql语句,或是换一种方式来写?
大概意思就是删除table1中table2不存在的数据。
1.id已经建立了索引
2.表中数据10w条朝上
如果数据量小的话,此sql语句是可以很快执行的。
有什么好的办法优化此sql语句,或是换一种方式来写?
大概意思就是删除table1中table2不存在的数据。
可以考虑将not in改写成not exists。。
where not exists (select 1 from table2 b where a.id = b.id);