我有两张桌子 - products
和product_categories
。
这些表格加入products
。product_id
= product_categories
。product_id
。
我想在表published
中更新条件products
= 100的字段product_categories.product_categories
。
答案 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;