我有两张 table ...
table1 (id, item, price) 值:
id | item | price
-------------
10 | book | 20
20 | copy | 30
30 | pen | 10
....table2 (id, item, price) 值:
id | item | price
-------------
10 | book | 20
20 | book | 30
现在我想:
update table1
set table1.Price = table2.price
where table1.id = table2.id
and table1.item = table2.item.
我该怎么做?
最佳答案
应该这样做:
UPDATE table1
SET table1.Price = table2.price
FROM table1 INNER JOIN table2 ON table1.id = table2.id
你也可以试试这个:
UPDATE table1
SET price=(SELECT price FROM table2 WHERE table1.id=table2.id);
关于sql - 根据条件用另一个表的列更新列值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1746125/