这是我的模拟数据
Table 1 Table 2
Column 1 Column 2 Column 1 Column 2
111 AAA 111 AAA
111 BBB 111 BBB
222 AAA 111 CCC
... 222 AAA
...
我想要表2中表1中的'children'(Column2),表1中没有。在这种情况下,我需要'111 CCC'
。
答案 0 :(得分:0)
您可以使用WHERE NOT EXISTS
:
Select T2.*
From Table2 T2
Where Not Exists
(
Select *
From Table1 T1
Where T1.Column1 = T2.Column1
And T1.Column2 = T2.Column2
)
答案 1 :(得分:0)
你可以尝试“不在”:
select column1, column2
from table2
where column2 not in (select column2 from table1)
答案 2 :(得分:0)
SELECT *
FROM table1 t1
RIGHT JOIN table2 t2
on t1.Col1 = t2.col1
AND t1.Col2 = t2.Col2
WHERE t1.Col1 is NULL
AND t1.Col2 is NULL
答案 3 :(得分:0)
我会使用CONCAT。我阅读你的问题的方式,你不只是检查CCC在表1中,而是你想知道111和CCC的组合是否在表1中。你可以这样做:
SELECT column1, column2
FROM table2
WHERE CONCAT(column1, column2)
NOT IN
(SELECT CONCAT(column1, column2)
FROM table1)