Oracle 为什么这两个select语句没有给出相同的答案
我正在使用oracle 11g。我想知道为什么这两个问题给出不同的答案 逻辑上它们是相同的:Oracle 为什么这两个select语句没有给出相同的答案,oracle,oracle11g,Oracle,Oracle11g,我正在使用oracle 11g。我想知道为什么这两个问题给出不同的答案 逻辑上它们是相同的: select * from tableA where exists (select * from tableB where tableA.ID != tableB.ID); select * from tableA where not exists (select * from tableB where tableA.ID = tableB.ID); 在第一个例子中,我选
select * from tableA where
exists (select * from tableB where tableA.ID != tableB.ID);
select * from tableA where
not exists (select * from tableB where tableA.ID = tableB.ID);
在第一个例子中,我选择了所有不存在的东西
在第二个例子中,我没有选择所有存在的东西
注意:存在已更改为不存在,并且!=改为=
看起来一样,对吗?但是它们给出了完全不同的答案第一个语句返回的A值不同于任何B值。
第二条语句返回的A值不同于所有B值。此语句可能会返回A中的所有值:
select *
from tableA
where exists (select * from tableB where tableA.ID != tableB.ID);
只有当一行与TableB中ID值为非空的所有行相同时,该行才会失败匹配。因此,如果TableB中至少有两行ID不同,则tableA中的所有行都将返回
本声明:
select *
from tableA
where not exists (select * from tableB where tableA.ID = tableB.ID);
表示表B中没有与表A中的id匹配的id。99%的情况下,这就是您想要的。+1,但第一种情况下可能有多行:第二行的ID字段中必须包含null。