MySQL更新了表2中表1中ID匹配的详细信息

时间:2015-06-01 13:39:20

标签: mysql

我已经看过这里发布的类似问题的其他解决方案,但无法找到有效的方法。

我在一张包含70k +产品的表格中更新价格,我已将新价格导入新表格以更新它们

Table 1: Products
Product, Description, Price, Updated

Table 2: Prices_2015
Product, Description, Price

产品是唯一标识符,产品代码,表1中的价格和描述需要使用表2中的更新,表1中的Updated字段需要具有刚刚添加的UNIX时间戳。

感谢任何帮助!

3 个答案:

答案 0 :(得分:0)

UPDATE `Products` a
JOIN `Prices_2015` b ON `a`.`Product` = `b`.`Product`
SET `a`.`Price` = `b`.`Price`
   ,`a`.`Description` = `b`.`Description`
   ,`a`.`Updated` = NOW();

答案 1 :(得分:0)

您可以通过将两个表调用到UPDATE来轻松完成,但实际上只更新其中一个表中的字段:

UPDATE Products p, Prices_2015 pr
SET p.Price = pr.Price, p.Description = pr.Description, p.Updated = NOW()
WHERE p.Product = pr.Product

答案 2 :(得分:0)

根据您的查询问题,您希望在price_2015的基础上更新产品表。这两个表都有独特的产品。

UPDATE Products
INNER JOIN Prices_2015 ON (Products.Product = Prices_2015.Product)
SET Products.Price = Prices_2015.Price

希望这会有所帮助。