当前位置: 代码迷 >> Sql Server >> 请教,怎么优化not in
  详细解决方案

请教,怎么优化not in

热度:40   发布时间:2016-04-27 16:44:41.0
请问,如何优化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)
  相关解决方案