我有两个表,其中表1包含4列,表2包含8列。我在table1中有两列,我想将它们与table2中的两列进行比较。
Table 1 have column1 and column2 (that needs to be compared)
Table 2 have column6 and column7 (that needs to be compared)
我需要比较这两列的组合。我试着执行下面的查询,但它不起作用
Select * from table1
where column1, column2 NOT IN (Select column6, column7 from table2)
如何比较这两个表中的两列?
发布于 2015-03-06 04:20:26
尝试使用减号语句。这将为您提供来自table1的第一个select语句的所有结果,这些结果不在table2的第二个select语句中。
select column1, column2 from table1
minus
select column6, column7 from table2
发布于 2020-04-20 22:30:15
Except显示了两个表之间的差异( Oracle人员使用减号代替except,并且语法和用法是相同的)。它用于比较两个表之间的差异。例如,让我们看看这两个表之间的区别
SELECT * FROM
table1
EXCEPT
SELECT * FROM
table2
发布于 2015-03-06 15:50:37
NOT EXISTS
是NOT IN
的“空安全”版本。如果您指的是column1和column2在table2中不在同一行的组合:
select *
from table1
where NOT EXISTS (select 1 from table2
where table1.column1 = table2.column6
and table1.column2 = table2.column7)
或者,如果您的意思是column1和column2值在table2中甚至不能在不同的行中:
select *
from table1
where NOT EXISTS (select 1 from table2
where table1.column1 = table2.column6)
and NOT EXISTS (select 1 from table2
where table1.column2 = table2.column7)
https://stackoverflow.com/questions/28886856
复制相似问题