求一条两个表之间的更新语句

themass 2006-03-14 10:01:33
sqlserver2000数据里有t1,t2两个表
t1的结构如下
id name fatherid
1 测试一 001
2 测试二 002
3 其他测试 003

t2的结构如下
id name
1 测试一
2 测试二

说明:t1的id并不等于t2的id

我想用一条更新语句更新t2表更新后的结果希望如下
id name
1 001
2 002
也就是只把t2表的name更新为t1表的fatherid,条件为t2.name=t1.name

我写了类似的更新语句
update t2 set t2.name=t1.fatherid where t2.name=t1.name
可是报:列前缀 't1' 与查询中所用的表名或别名不匹配。的错误

请问这样的更新怎么写呀
...全文
62 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
firefox_1983 2006-03-14
  • 打赏
  • 举报
回复
update t2 set t2.name=t1.fatherid from t1,t2 where t2.name=t1.name
lsqkeke 2006-03-14
  • 打赏
  • 举报
回复
update t2 set name=t1.fatherid from t1 where t2.name=t1.name
Alang_79 2006-03-14
  • 打赏
  • 举报
回复
update t2 set t2.name=(SELECT t1.fatherid FROM T1 where t1.name=t2.name)

34,593

社区成员

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

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