使用多个内部联接更新查询

时间:2019-04-15 20:50:51

标签: c# sql

我想使用多个内部联接查询来更新表,但是当我通过内部关键字附近的错误不正确的语法编写查询时,便会

     Update inventory_detail INNER JOIN inventory 
    ON inventory_detail.inventory_id = Inventory.Inventory_id 
    INNER JOIN Ingredients 
    ON Inventory.Inventory_id=Ingredients.invenotry_id 
         SET inventory_detail.Quantity=inventory_detail.Quantity-1 
        WHERE inventory_detail.loc_id =1 AND Ingredients.item_id=27 ;

ERD diagram

1 个答案:

答案 0 :(得分:0)

将查询更改为:

UPDATE inventory_detail
SET Quantity = Quantity - 1
FROM inventory_detail
    INNER JOIN inventory
        ON inventory_detail.inventory_id = Inventory.Inventory_id
    INNER JOIN Ingredients
        ON Inventory.Inventory_id = Ingredients.invenotry_id
WHERE inventory_detail.loc_id = 1
      AND Ingredients.item_id = 27;