问题描述
我有时在我的sql查询中互换使用NOT IN
和NOT EXIST
,并且两者都产生相同的结果. NOT EXIST
背后的逻辑与NOT IN
相同吗?因为我认为NOT IN
...(在子查询中被评估为或")等于NOT EXIST
(也被评估为或")?还是我想念什么?
I sometimes interchanged the use of NOT IN
and NOT EXIST
in my sql queries and both yield the same result. Is the logic behind the NOT EXIST
the same as NOT IN
? Because I think that NOT IN
... (is being evaluated as "OR" inside the subqueries) is equal to NOT EXIST
(which is also evaluated as "OR")? Or am i missing something?
推荐答案
您可能会对本文感兴趣:
This article may be of interest to you:
简而言之,NOT IN
与NOT EXISTS
在两个处理子查询返回的NULL
值的方式上稍有不同.
In a nutshell, NOT IN
is slightly different from NOT EXISTS
in the way the two handle NULL
values returned by the subquery.
如果没有NULL
值,它们都对NESTED LOOP ANTI JOIN
执行某种操作,但是NOT IN
效率更高.
If there are no NULL
values, they both perform a kind on NESTED LOOP ANTI JOIN
, but NOT IN
is a little bit more efficient.
这篇关于mysql NOT IN和NOT EXIST不一样吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!