我有两个包含多列的表,但我只关心两列(profile1和profile2)。两个表之间都没有关系。我想看看
profile1和profile2都存在于表1和表2中
profile1和profile2都存在于表1中,但不存在于表2中
profile1和profile2都存在于表2中,但不存在于表1中
表1
profile1 profile2
表2
profile1 profile2
我不确定我做得是否正确。
profile1和profile2都存在于表1和表2中
SELECT DISTINCT T2.profile1, T2.profile2
FROM table2 as T2
WHERE EXISTS
(
SELECT DISTINCT T1.profile, T1.profile2
FROM table1 as T1
WHERE T2.profcode = T1.profcode
AND T2.connecting_profcode = T1.connecting_profcode
);
存在于t1但不存在于t2
SELECT DISTINCT T2.profile1, T2.profile2
FROM table2 as T2
WHERE NOT EXISTS
(
SELECT DISTINCT DISTINCT T1.profile1, T1.profile2
FROM table1 as T1
WHERE T2.profile1 = T1.profile1
AND T2.profile2 = T1.profile2
);
存在于t2,但不存在于t1
SELECT DISTINCT T1.profile1, T1.profile2
FROM table1 as T1
WHERE NOT EXISTS
(
SELECT DISTINCT T2.profile1, T2.profile2
FROM table2 as T2
WHERE T1.profile1 = T2.profile1
AND T1.profile2 = T2.profile2
);
2条答案
按热度按时间gg0vcinb1#
你想分开吗
SELECT
声明1.profile1和profile2都存在于表1和表2中
2.profile1和profile2都存在于表1中,但不存在于表2中
3.profile1和profile2都存在于表2中,但不存在于表1中
yhived7q2#
您也可以这样做: