找出A表中不等于B表的数据

题目

A,B两表,找到ID字段中,存在A表,但不存在B表的数据。
A表有13W数据,去重后3W。B表共2W数据 且有索引

方法一 not in 易于理解 速度慢

select distinct A.id from A where id not in (select id from B)

方法二 is not null 速度适中

select A.id from A left join B on A.id=B.id on B.id is not null

方法三 过滤

select * from A where (select count(1) from B where A.id=B.id)=0

三种方法第三种速度最快,如果业务允许可优选第三种。


版权声明:本文为weixin_43437049原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。