mysql更新

inkz8wg9  于 2021-06-21  发布在  Mysql
关注(0)|答案(3)|浏览(194)

我的问题是:

UPDATE 
    `product_pricing` 

SET `formula_id`= '2'

WHERE 1
SELECT

product_pricing.id,
product_pricing.formula_id,
product_pricing.vat_calculated,

products_ids.id,
products_ids.link_id,

product_attributes.fty_id,
product_attributes.size_id,

product_sizes.size_id,
product_sizes.wheel

FROM product_pricing 

LEFT JOIN products_ids ON product_pricing.id = products_ids.id
LEFT JOIN product_attributes ON products_ids.link_id = product_attributes.fty_id
LEFT JOIN product_sizes ON product_attributes.size_id = product_sizes.size_id

WHERE

product_sizes.wheel = '13'

如何将select查询与update查询合并?
我只需要更新那些 product_sizes.wheel = '13' 但是要得到这个信息,我需要一些左连接。

3wabscal

3wabscal1#

您可以将此更新与left join和where一起使用

update product_pricing 
LEFT JOIN products_ids ON product_pricing.id = products_ids.id
LEFT JOIN product_attributes ON products_ids.link_id = product_attributes.fty_id
LEFT JOIN product_sizes ON product_attributes.size_id = product_sizes.size_id
SET product_pricing.formula_id= '2'
WHERE

product_sizes.wheel = '13'
cdmah0mi

cdmah0mi2#

我想是的 INNER JOIN 此处需要:

update product_pricing 
INNER JOIN products_ids ON product_pricing.id = products_ids.id
INNER JOIN product_attributes ON products_ids.link_id = product_attributes.fty_id
INNER JOIN product_sizes ON product_attributes.size_id = product_sizes.size_id
SET product_pricing.formula_id= '2'
WHERE product_sizes.wheel = '13'
bfrts1fy

bfrts1fy3#

试试这个

update product_pricing p
LEFT JOIN products_ids pi ON p.id = pi.id
LEFT JOIN product_attributes pa ON pi.link_id = pa.fty_id
LEFT JOIN product_sizes ps ON pa.size_id = ps.size_id
SET p.formula_id= '2'
WHERE
ps.wheel = '13'

相关问题