开发者

Updating one mysql table based on calculations using variables in another table

开发者 https://www.devze.com 2022-12-10 05:13 出处:网络
I\'m trying to update one table based on values in another table. What\'s wrong with the following request? Error: Unknow开发者_JAVA技巧n column \'source.col3\' in \'where clause\'

I'm trying to update one table based on values in another table. What's wrong with the following request? Error: Unknow开发者_JAVA技巧n column 'source.col3' in 'where clause'

UPDATE target 
  SET target.col1 = source.col1 * target.col2,
WHERE target.col3 = source.col3


Well, for one you're not specifying 'source' as a table anywhere.

MySQL actually supports multiple table update, so you could write your code as:

UPDATE target, source
   SET target.col1=source.col1*target.col2
 WHERE target.col3=source.col3

Now whether that would actually do what you want I can't tell without knowing more about your tables.

0

精彩评论

暂无评论...
验证码 换一张
取 消