SQL如何比较两个不同表中的两列

mzb*_*bib 8 mysql sql sql-server

我有两个表,其中表 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) 
Run Code Online (Sandbox Code Playgroud)

我需要比较两列的组合。我试图做下面的查询,但它不起作用

Select * from table1 
where column1, column2 NOT IN (Select column6, column7 from table2)
Run Code Online (Sandbox Code Playgroud)

如何比较两个表中的两列?

jue*_*n d 0

我能想到的比较最少的查询是

Select t1.* 
from table1 t1
left join table2 t2 on t1.column1 in (t2.column6, t2.column7)
                    or t1.column2 in (t2.column6, t2.column7)
where t2.column6 is null
Run Code Online (Sandbox Code Playgroud)