日期:2014-05-18  浏览次数:20360 次

请问,如何优化not in?
这条sql应该如何优化,使其效率最高呢?

select   DISTINCT(name)   from   AA   where   name   not   in((select   name   from   BB)   union   (select   name   from   CC))



------解决方案--------------------

select distinct name
from AA as tmp
where not exists(select 1 from BB where name=tmp.name) and
not exists(select 1 from CC where name=tmp.name)