Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Oracle SQL提供不同的输出_Sql_Oracle_Subquery - Fatal编程技术网

Oracle SQL提供不同的输出

Oracle SQL提供不同的输出,sql,oracle,subquery,Sql,Oracle,Subquery,有人能解释一下为什么这些ORACLE SQL查询会给出不同的输出吗 select * from table2 where not exists(select 1 from table1 a,table2 b where a.name = b.name and a.age = b.age) select * from table2 b where not exists(select 1 from table1 a where a.name = b.name and a.age = b.age

有人能解释一下为什么这些ORACLE SQL查询会给出不同的输出吗

select * from table2
where  not exists(select 1 from table1 a,table2 b where a.name = b.name and a.age = b.age)


select * from table2 b
where not exists(select 1 from table1 a where a.name = b.name and a.age = b.age)

第一条语句在subselect中本地检查是否存在两个表都有公共记录的记录。如果是,则返回表2的所有记录。否则,它将不返回任何行。外部table2和exists中的subselect之间没有关系,您使用两个不相关的table2实例。 因此,这是一个全有或全无的结果:如果exists有记录,那么外部where条件对于外部表2的所有行都为true,否则对于外部表2的所有行都为false

第二个查询返回表2的相关记录,这些记录在表1中有一个公共记录。

Query1检查表1和表2的联接外数据是否不存在,如果存在,则获取表2的所有记录,如果联接失败且没有匹配项,或者如果至少找到一个匹配项,则获取任何记录


而查询2,对于表2中的每一行,与表1连接并检查它是否不存在。所以结果是显而易见的!只有符合条件的记录才会出来。

子查询中的来源在哪里?它是否运行良好?是什么使Oracle SQL不能很好地回答这个问题?查询是不同的,因此outputs@T.S.但是这个查询与其中一个完全相同,只是使用。。。退出选择5。。。而不是退出选择1。。。也将不同于原始,但给出相同的结果-