mysql多左连接更新

时间:2013-07-02 11:59:55

标签: mysql

UPDATE  p.id_product, p.quantity, p.price,p.on_sale, p.additional_shipping_cost, p.active,
                        p.available_for_order, p.show_price, p.date_upd,
                        pl.id_product, pl.name,pl.description, pl.description_short,
                        cl.id_category, cl.name,
                        ps.is_product,ps.price
                    LEFT JOIN ps_product_lang pl ON (p.id_product = pl.id_product)
                    LEFT JOIN ps_category_lang cl ON (p.id_category_default = cl.id_category)
                    LEFT JOIN ps_product_shop ps ON (p.id_category_default = ps.id_product)

                SET     
                        p.quantity = \"$quantity\", 
                        p.price = \"$price\", 
                        p.additional_shipping_cost = \"$additional_shipping_cost\",
                        p.active = \"$active\", 
                        p.available_for_order = \"$available_for_order\", 
                        p.show_price = \"$show_price\",
                        pl.name=\"$name\", 
                        pl.description=\"$description\",
                        pl.description_short=\"$description_short\",
                        p.date_upd = NOW(),
                        cs.price=\"$price\", 
                        cs.date_upd = NOW() 
                WHERE p.id_product = $i

1 个答案:

答案 0 :(得分:0)

正确的syntax of the update statement

update FooTable 
 set fooField1 = fooValue
where foofield2 = fooCondition

所以,您的查询必须看起来像这样,没有选择的字段......

UPDATE  FooTable p
                    LEFT JOIN ps_product_lang pl ON (p.id_product = pl.id_product)
                    LEFT JOIN ps_category_lang cl ON (p.id_category_default = cl.id_category)
                    LEFT JOIN ps_product_shop ps ON (p.id_category_default = ps.id_product)

                SET     
                        p.quantity = \"$quantity\", 
                        p.price = \"$price\", 
                        p.additional_shipping_cost = \"$additional_shipping_cost\",
                        p.active = \"$active\", 
                        p.available_for_order = \"$available_for_order\", 
                        p.show_price = \"$show_price\",
                        pl.name=\"$name\", 
                        pl.description=\"$description\",
                        pl.description_short=\"$description_short\",
                        p.date_upd = NOW(),
                        cs.price=\"$price\", 
                        cs.date_upd = NOW() 
                WHERE p.id_product = $i