这个SQL语句怎么写?

jasper_liu 2003-03-28 11:06:27
我有一个表的数据需要根据另一个表中的数据更新:
如下:
表1:
[column 1] [column2]
1 null
2 null
3 null

表2:
[column 1] [column2]
1 1
2 2
3 3

现在要把表1的第2列的值更新为表2中的对应的第2列的值

如何写这个update语句?
...全文
76 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
shrtman 2003-03-28
  • 打赏
  • 举报
回复
update table2

set table1.column2=table2.column2

where table1.column1=table2.column1 and table1.column1=2
yenight 2003-03-28
  • 打赏
  • 举报
回复
OK Din
chpeng 2003-03-28
  • 打赏
  • 举报
回复
update table2
set table1.column2=table2.column2
where table1.column1=table2.column2
zqllyh 2003-03-28
  • 打赏
  • 举报
回复
update a set a.c2=b.c2 from a,b where a.c1=b.c1
zijun28 2003-03-28
  • 打赏
  • 举报
回复
试试这个呢?
update table1 as a set a.column2='slect column2 from table2 as b where b.column1=a.column1'
保证select语句查找出的记录为一条才可以

22,300

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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