具有特定条件的UPDATE表

时间:2014-10-01 08:29:48

标签: mysql sql

我有两张桌子 - productsproduct_categories

这些表格加入productsproduct_id = product_categoriesproduct_id

我想在表published中更新条件products = 100的字段product_categories.product_categories

2 个答案:

答案 0 :(得分:0)

试试这个

UPDATE bjvui_virtuemart_products as prod
  INNER JOIN bjvui_virtuemart_product_categories as cat
  ON prod.virtuemart_product_id =cat.virtuemart_product_id
SET prod.published ={value}
WHERE cat.virtuemart_category_id=100

答案 1 :(得分:0)

将UPDATE与JOIN一起使用

UPDATE TABLEA a 
JOIN TABLEB b ON a.join_colA = b.join_colB  
SET a.columnToUpdate = [something]
WHERE a.someColumn = [some_value]

对于你的情况

UPDATE bjvui_virtuemart_products AS p
INNER JOIN bjvui_virtuemart_product_categories AS c ON 
p.virtuemart_product_id = c.virtuemart_product_id
SET p.published = "your_value"
WHERE c.virtuemart_category_id = 100;