求用一个表更新另一个表的SQL语句

chengchangwei 2004-10-13 02:43:19
table1 table2
id1 status id1 status
1 y 1 A
2 z 2 b
现在当table2.id1=table1.id1时,要用Table2的status的值代替table1中的status的值.
即更新后得到:
table1
id1 status
1 A
2 b

...全文
613 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
hqcsx 2004-10-13
  • 打赏
  • 举报
回复
你可以试一下:
update table1 set table1.status=table2.status where table1.id=table2.id
lsxaa 2004-10-13
  • 打赏
  • 举报
回复
update table1 set status=table2.status
from table2
where table1.id1=table2.id1
heibai520 2004-10-13
  • 打赏
  • 举报
回复
update a set a.status=b.status
from table1 a,table2 b
where a.id1=b.id1
shuijun 2004-10-13
  • 打赏
  • 举报
回复
update table1 set a.status = b.status
from table1 a inner join table2 b
on a.idl = b.idl
hsh_boy 2004-10-13
  • 打赏
  • 举报
回复
upadte table1 set table1.status =table2.status
from table1,table2
where table1.idl=table2.idl
freddy2003 2004-10-13
  • 打赏
  • 举报
回复
up
zjcxc 元老 2004-10-13
  • 打赏
  • 举报
回复
update a set a.status=b.status
from table1 a,table2 b
where a.id1=b.id1
WangZWang 2004-10-13
  • 打赏
  • 举报
回复
update a set a.status=b.status
from table1 as a
inner join table2 as b
on a.id1=b.id1

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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