现在的位置: 网页制作教程网站制作教程 >正文
SQL语句教程

比较两个表不同数据差异的sql语句

发表于2018/10/17 网站制作教程 0条评论 ⁄ 热度 11,898℃

目前有两个表A、B表,两表中数据既有相同的,也有不同的,那么如何通过sql语句筛这些差异的数据。

找出A表中不存在于B表的记录

select * from A where not exists(select 1 from B where B.col1 = A.col1 and B.col2 = A.col2 and B.col3 = A.col3)

找出B表中不存在于A表的记录

 select * from B where not exists(select 1 from A where B.col1 = A.col1 and B.col2 = A.col2 and B.col3 = A.col3)

通过以上两条sql语句,就可以对比出两张表中不同的差异数据。

  • 暂无评论