读书人

请教怎么优化not in

发布时间: 2012-02-26 20:19:44 作者: rapoo

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

读书人网 >SQL Server

热点推荐