Convert UPDATE with INNER JOIN from SQL for use in MySQL

前端 未结 4 2061
醉酒成梦
醉酒成梦 2021-01-07 03:40

I\'d like to convert this for us in MySQL:

UPDATE product 
SET price = 12.95 
FROM product 
    INNER JOIN product_to_category ON product.product_id = produc         


        
4条回答
  •  情话喂你
    2021-01-07 04:05

    The general syntax for a multiple-table UPDATE statement is

    UPDATE 
        (INNER|LEFT|RIGHT|...) JOIN  ON  
    SET =
    WHERE 
    
    
    

    So your statement should work if you rewrite it to

    UPDATE product 
        INNER JOIN product_to_category ON product.product_id = product_to_category.product_id
        INNER JOIN category ON product_to_category.category_id = category.category_id AND category.parent_id = 39
    SET price = 12.95 
    

    (untested, I don't have a mysql instance at hand)

    提交回复
    热议问题