如何从另一个 table MySQL 更新 table 中的值
How to update values in a table from another table MySQL
我创建了 table_1,其中包含产品列表以及价格和数量列(目前都是 NULL
作为空值的默认值)
我还有另一个 table (table_2),具有相同的列,其中包含有关每种产品的价格和数量的信息。
如何使用来自 table_2 的信息更新 table_1?
我尝试将子查询与 UPDATE
和 INSERT INTO
命令一起使用 - 两者都不起作用。
我把两个 table 粘贴在这里:
https://justpaste.it/8qusd
考虑 update/join 语法:
update table1 t1
inner join table2 t2 on t2.id = t1.id
set t1.price = t2.price, t1.quantity = t2.quantity
我创建了 table_1,其中包含产品列表以及价格和数量列(目前都是 NULL
作为空值的默认值)
我还有另一个 table (table_2),具有相同的列,其中包含有关每种产品的价格和数量的信息。
如何使用来自 table_2 的信息更新 table_1?
我尝试将子查询与 UPDATE
和 INSERT INTO
命令一起使用 - 两者都不起作用。
我把两个 table 粘贴在这里: https://justpaste.it/8qusd
考虑 update/join 语法:
update table1 t1
inner join table2 t2 on t2.id = t1.id
set t1.price = t2.price, t1.quantity = t2.quantity