比如:A,B两表,找到ID字段中,存在A表,但不存在B表的数据。
A表共13w,去重后3w,
B表共2W,且有索引
方法一
not in,易理解,效率低,时间:1.395s
select distinct A.id from A where A.id not in(select id from B)
方法二
left...join...on ,B.id isnull 时间:0.739s
select A.ID from A left join B on A.ID=B.ID where B.ID is null
方法三
效率高,时间:0.57s
select * from A where (select count(1) as num from B where A.ID = B.ID) = 0