急! 比较两个相同结构的table的不同数据.

zhangzs8896 2007-07-23 09:52:12
有两个相同结构的数据表:
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
...全文
215 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
meiZiNick 2008-05-01
  • 打赏
  • 举报
回复
不会,帮顶
ahjoe 2008-02-19
  • 打赏
  • 举报
回复
结果有两个 ID ?
中国风 2008-02-01
  • 打赏
  • 举报
回复
---楼主的显示不正确哟。。以下方法对比
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)
)
leo_lesley 2007-07-23
  • 打赏
  • 举报
回复
结果的原值是怎么来的,还有下面两条也不一样阿?怎么不显示

tb1的结果
1 wang bj
tb2的结果
1 wang sh
昵称被占用了 2007-07-23
  • 打赏
  • 举报
回复
确认下 结果 有没贴错

或者解释下 结果 怎么来的

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧