首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

两个表连接更新解决办法

2012-03-18 
两个表连接更新我有A表B表A表字段 spidspbhsp0011001sp0021002sp0031003B表字段 spidspbhspbh_newsp001100

两个表连接更新
我有A表B表
A表字段 spid spbh  
  sp001 1001
  sp002 1002
  sp003 1003

B表字段 spid spbh spbh_new
  sp001 1001 1011
  sp003 1003 1013

当b.spid=a.spid 时,更新A表,得出结果
A表 spid spbh
  sp001 1011
  sp002 1002
  sp003 1013

这个语句怎么写?

[解决办法]

SQL code
update aset a.spbh=b.spbh_newfrom bwhere b.spid=a.spid
[解决办法]
SQL code
update aset a.spbh=b.spbh_newfrom a, bwhere b.spid=a.spid
[解决办法]
探讨
从楼主的数据看,spbh应该也要关联

[解决办法]
SQL code
update A表    set spbh = (select spbh_new from B表 where spid =A表.spid) 

热点排行