比较sql中的2个表 [英] Compare 2 tables in sql
本文介绍了比较sql中的2个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两张桌子,A1 和 A2.我想比较这两个表.我尝试了内连接,但它没有给出所需的结果.
I have two tables, A1 and A2. I want to compare these two tables. I tried inner join but it doesn't give the required result.
这些是这些表中的数据,
These are the data in these tables,
表 A1
No. Address
1 abc
1 abc
1 def
1 def
表 A2
No. Address
1 def
1 abc
1 abc
1 def
这两个表只能使用No.
列连接.所以如果我使用 INNER JOIN 它会给出 16 行.我不想那样,我只想显示 4 行.这应该是输出:
These two tables can only be joined by using No.
column. So if I use INNER JOIN it gives 16 rows. I don't want that, I want only 4 rows to be displayed. This should be the output:
No. Address eq
1 abc #
1 abc *
1 abc #
1 abc #
如果 A1 中的地址等于 A2,则显示最后一列
Last column is displayed if address in A1 is equal to A2
推荐答案
搜索A1表中存在但A2表中不存在的记录:
Search for records that exist in A1 table but not in A2 table:
SELECT * FROM A1 WHERE NOT EXISTS (SELECT * FROM A2 WHERE A2.Id = A1.Id)
这篇关于比较sql中的2个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文