如果在两表联合查询后更新数据
刚学习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)
查询结果提示:
子查询返回的值多于一个。当子查询跟随在 =、!=、<、<=、>、>= 之后,或子查询用作表达式时,这种情况是不允许的。
[解决办法]
update table1 set b.kucun=a.shuliang from table1 b,table2 a where b.name=a.t2name
[解决办法]
update table1 set kucun=(select u.shuliang from table1 d,table2 u where d.name=u.t2name)
[解决办法]
UPDATE a SET a.kucun = b.shuliang FROM table1 a INNER JOIN table2 b ON a.NAME = b.NAME