如何获取两个表中不匹配的记录
问题描述:
我有两张桌子
table1
id
1
2
3
4
表2
id
1
2
我需要获得两个匹配的记录表格使用连接而不是任何其他方法。
答案应为3,4
I have a two tables
table1
id
1
2
3
4
Table2
id
1
2
I need to get the records which does nt match in two tables using joins not any other method.
The answer should be 3,4
答
尝试:
Try:
SELECT ID FROM Table1 LEFT JOIN Table2 ON Table1.Id=Table2.Id WHERE Table2.Id IS NULL
SELECT * FROM Table2
EXCEPT
SELECT * FROM Table1