简体   繁体   中英

SQL Update syntax error with join

I have a table menu_item with id, and min price. I have another table menu_item_variant with menu_item_id, variant_value_id and price1. I want to set menu_item.min_price = menu_item_variant.price1 when variant_value_id=1550. I am using the following command but it's giving me an error. I can't see what is wrong with it. Please help

update menu_item set menu_item.min_price = menu_item_variant.price1 
from menu_item join menu_item_variant 
on menu_item.id = menu_item_variant.menu_item_id 
where variant_value_id = 1550;

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from menu_item join menu_item_variant on menu_item.id = menu_item_variant.menu_i' at line 1

The proper syntax in MySQL does not use from :

update menu_item join
       menu_item_variant
       on menu_item.id = menu_item_variant.menu_item_id
    set menu_item.min_price = menu_item_variant.price1
where variant_value_id = 1550;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM