tb2:
ID Name Address
1 zhang bj
1 wang sh
1 song bj
想得到的结果是:
字段名 原值 新值
ID bj sh
ID 1 1
Name song song
address bj bj
...全文
2155打赏收藏
急! 比较两个相同结构的table的不同数据.
有两个相同结构的数据表: Tb1,Tb2 结构为: ID,Name,address 数据: tb1 ID Name Address 1 zhang bj 1 wang bj tb2: ID Name Address 1 zhang bj 1 wang sh 1 song bj 想得到的结果是: 字段名 原值 新值 ID bj sh ID 1 1 Name song song address bj bj
---楼主的显示不正确哟。。以下方法对比
select [表]='t1',* from t1 where binary_checksum(*) not in(select binary_checksum(*) from t2)
union all
select '表'='t2',* from t2 where binary_checksum(*) not in(select binary_checksum(*) from t1)
-----------
05用except
select * from t1
except
select * from t2
union all
select * from t2
except
select * from t1
----------或
select * from t1 where not exists(select 1 from t2 where ID =t1.ID and Name =t1.Name and Address =t1.Address)
union all
select * from t2 where not exists(select 1 from t1 where ID =t1.ID and Name =t1.Name and Address =t1.Address)
)