把表1的内容更换为表2内容的问题...

[复制链接]
查看11 | 回复1 | 2002-6-8 09:40:00 | 显示全部楼层 |阅读模式
有两张表,现想根据表2的内容更新表1的内容(只修改不同部分),基于性能的考量,这里不考虑用游标。
我的SQL语句为:
update test1 set age = (select age from test2 where depart = test1.depart and name = test1.name),

tall = (select tall from test2 where depart = test1.depart and name = test1.name)
where exists (select 1 from test2 where name = test1.name and depart = test1.depart

and (age != test1.age or tall != test1.tall));
有没有更好的办法?
多谢了
回复

使用道具 举报

千问 | 2002-6-8 09:40:00 | 显示全部楼层
a little bit improved update statement:
update test1 set (age, tall) = (select age, tall from test2 where depart = test1.depart and name = test1.name)
where exists (select 1 from test2 where name = test1.name and depart = test1.depart
and (age != test1.age or tall != test1.tall));
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行