not exists不能仅仅理解为差集

要看以谁为主表,

见如下示例,同样的表,主表不一样,结果不一样:

这里假设left表数据1050条,right表数据1000条。

select * from [left]  l
where not exists (
select * from [right] r
where l.name=r.name
)
结果为50条
-----------------------------
--下面这个例子充分说明,not exists不能单单理解为差集
select * from [right]  r
where not exists (
select * from [left] l
where l.name=r.name
)
结果为空集

猜你喜欢

转载自wandejun1012.iteye.com/blog/1561773