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

如果在两表联合查询后更新数据解决方法

2012-10-21 
如果在两表联合查询后更新数据刚学习sql,属于菜鸟水平,求帮忙解决,不胜感激!环境:table1字段namekucuntabl

如果在两表联合查询后更新数据
刚学习sql,属于菜鸟水平,求帮忙解决,不胜感激!

环境:
table1 字段 name kucun 
table2 字段 t2name shuliang

现在想更新table1的库存数为table2中的shuliang值,满足条件,table2中的t2name=table1中的name。


update table1 set kucun=(select u.shuliang from table1 d,table2 u where d.name=u.t2name)

查询结果提示:

子查询返回的值多于一个。当子查询跟随在 =、!=、<、<=、>、>= 之后,或子查询用作表达式时,这种情况是不允许的。


[解决办法]

SQL code
update table1 set b.kucun=a.shuliang from table1 b,table2 a where b.name=a.t2name
[解决办法]
SQL code
update table1 set kucun=(select u.shuliang from table1 d,table2 u where d.name=u.t2name)
[解决办法]
SQL code
UPDATE  a SET     a.kucun = b.shuliang FROM    table1 a         INNER JOIN table2 b ON a.NAME = b.NAME 

热点排行
Bad Request.