我在两个单独的表中有两个字段需要更新为相同的值。没有过程等。这可以在单个查询中实现吗?
工作声明:
UPDATE product,product_shop SET
product_shop.price='737.96',
product.price='737.96',
product_shop.wholesale_price='479.67',
product.wholesale_price='479.67'
WHERE
product_shop.id_product=product.id_product AND
product_shop.id_product=14;
我希望的是:
UPDATE product,product_shop SET
product_shop.price=product.price='737.96',
product_shop.wholesale_price=product.wholesale_price='479.67'
WHERE
product_shop.id_product=product.id_product AND
product_shop.id_product=14;
最佳答案
MySQL 文档说明您可以做到 this ,如果您试图避免打印两次该值,您可以执行以下操作:
UPDATE product,product_shop SET
product_shop.price='737.96',
product.price=product_shop.price,
product_shop.wholesale_price='479.67',
product.wholesale_price=product_shop.wholesale_price
WHERE
product_shop.id_product=product.id_product AND
product_shop.id_product=14;
关于MySQL 更新多个具有相同值的字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15898149/