使用SQL从INNER JOIN转换UPDATE以在MySQL中使用 [英] Convert UPDATE with INNER JOIN from SQL for use in MySQL

查看:85
本文介绍了使用SQL从INNER JOIN转换UPDATE以在MySQL中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在MySQL中为我们进行转换:

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 = product_to_category.product_id 
    INNER JOIN category ON product_to_category.category_id = category.category_id 
        AND category.parent_id = 39

MySQL不喜欢FROM部分,而且我不确定INNER JOINs是否也可以按照编写的方式工作.

MySQL doesn't like the FROM portion, and I'm not sure that the INNER JOINs will work as written either.

推荐答案

UPDATE product 
SET price = 12.95 
WHERE product_id in
(SELECT product_id 
FROM product_to_category 
INNER JOIN category 
ON product_to_category.category_id = category.category_id 
WHERE category.parent_id = 39)

这篇关于使用SQL从INNER JOIN转换UPDATE以在MySQL中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆