首页 > 解决方案 > 使用内部联接从其他表中减去值

问题描述

我试图从另一个表中减去另一个值(对不起,满嘴)但是我开发的 SQL 不断抛出相同的错误:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'FROM products INNER JOIN order_details ON products.ItemID = order_details.Item' at line 2

这是我的代码:

UPDATE products SET Quantity = (products.Quantity - order_details.Quantity)
FROM products
INNER JOIN order_details
ON products.ItemID = order_details.ItemID
WHERE order_details.OrderID = 95 AND products.ItemID = order_details.ItemID;

它只是某人购买物品时的代码,它应该通过他们购买的任何东西的数量来减少产品表中的数量。任何帮助表示赞赏。

标签: mysqlsql

解决方案


thejoin是该子句updatenot 的一部分:SET

UPDATE products INNER JOIN order_details
ON products.ItemID = order_details.ItemID
SET Quantity = (products.Quantity - order_details.Quantity)
WHERE order_details.OrderID = 95;

推荐阅读