update 多表关联。

afeisky 2003-10-17 04:01:36
两个表结构是一样的,customer2是有最新的数据。
而customer1的数据要从customer2得到。根据id1,id2来判断。
customer1(id1,id2,name1,name2)
customer2(id1,id2,name1,name2)

现在我想根据customer2的数据更新到customer1中。

在SQL 2000中是这样写的,
update customer1
set name1=b.name1
name2=b.name2
select customer1 a,
customer2 b
where a.id1=b.id1
and a.id2=b.id2

这该怎么改? 谢谢
...全文
60 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
xinpingf 2003-11-20
  • 打赏
  • 举报
回复
我觉得where里面两表的顺序应该倒过来更好些

update customer1 a
set (name1,name2)=(select name1,name2 from customer2 b where id1=a.id1
and id2=a.id2)
tjwk 2003-11-20
  • 打赏
  • 举报
回复
up
beckhambobo 2003-11-20
  • 打赏
  • 举报
回复
update customer1 a
set (name1,name2)=(select name1,name2 from customer2 b where a.id1=b.id1
and a.id2=b.id2) where exists(select 1 from customer2 b where a.id1=b.id1
and a.id2=b.id2)
beckhambobo 2003-11-11
  • 打赏
  • 举报
回复
update customer1 a
set (name1,name2)=(select name1,name2 from customer2 b where a.id1=b.id1
and a.id2=b.id2)
yangqingdelphi 2003-11-11
  • 打赏
  • 举报
回复
楼上的方法正确!
jasoncheung 2003-11-11
  • 打赏
  • 举报
回复
update customer1 a
set (a.name1,a.name2)=(select b.name1 ,b.name2 from customer2 b
where a.id1=b.id1
and a.id2=b.id2 )
lifei88 2003-11-11
  • 打赏
  • 举报
回复
up
深圳李春雷 2003-11-11
  • 打赏
  • 举报
回复
update customer1 x
set (name1,name2)=(select name1,name2 from customer2 y where x.id1=y.id1 and x.id2=y.id2)

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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