首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

请教,怎么优化not in

2012-02-26 
请问,如何优化not in?这条sql应该如何优化,使其效率最高呢?selectDISTINCT(name)fromAAwherenamenotin((se

请问,如何优化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)

热点排行