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
本文介绍三种高效查询A表中不在B表中存在的ID的方法:使用not in、left join及子查询对比,展示不同方法的执行时间差异。
2944

被折叠的 条评论
为什么被折叠?



