大家早上好,
我已经编写了一个SQL查询来从要更新的数据库中获取所有数据,但是可以算出如何将更新语句放在这里。
SELECT product_id, product_title, prodcat_category_id, category_active, product_active from products
LEFT JOIN productcategories on products.product_id = productcategories.prodcat_product_id
LEFT JOIN categories on productcategories.prodcat_category_id = categories.category_id
WHERE category_active = 0
我想将所有这些结果更新为product_active 0,但是我从未在select连接中执行过update语句。
最佳答案
尝试以下查询
Update products set product_active = 0 where product_id IN
(
SELECT product_id from products
LEFT JOIN productcategories on products.product_id = productcategories.prodcat_product_id
LEFT JOIN categories on productcategories.prodcat_category_id = categories.category_id
WHERE category_active = 0
);
关于mysql - 选择联接的MYSQL更新,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22657716/