读书人

比较两个表中不同的数据,该怎么解决

发布时间: 2012-02-22 19:36:55 作者: rapoo

比较两个表中不同的数据
我有两张表,表中都有上千条数据,表结构一模一样,只是不知道两张表中哪个字段中的数据不一样,导致汇总出来的结果不一致,找出数据不一致的记录

[解决办法]
假设表A(col1, col2, col3) 表B(col1, col2, col3)

通过语句 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) 来找出A表中不存在于B表的记录

通过语句 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) 来找出B表中不存在于A表的记录

读书人网 >PB

热点推荐