求1sql脚本优化方法

求一sql脚本优化方法
本帖最后由 hwhtj 于 2014-12-15 14:57:36 编辑

select  from a where id not in (select distinct id from b)

------解决思路----------------------
select  from a where not exists (select 1 from b where id=a.id)

可以考虑给B表增加id的索引
------解决思路----------------------
引用:
使用not exists,只要找到一条存在的记录就停止了,不需要使用distinct
使用distinct需要先做去重处理,反而消耗了更多的时间

正解。