SQL Server 中的 'ANY' 和 'EXISTS' 有什么区别?

3

当我在运行时

select code from account where exists (select account from store)
except 
select code from account where code = any (select account from store)

它给我带来了两个结果,这意味着它们不相同。经过我的研究,我没有发现它们之间有任何区别。根据我的了解,“any”很少使用。是否有人可以帮助我解决这个问题?


2
= anyin 是相同的,所以你从未看到过它。 - Martin Smith
1个回答

4
这两个查询非常不同。
第一个查询根据子查询是否返回行或没有行来返回所有行或没有行。
你打算使用相关子查询:
select code from account where exists (select 1 from store where store.account = account.code)

这些应该是等价的。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接