我正在尝试使用以下查询更新表
update at_product A join
(
SELECT atbillfields.billeditemguid,count(*) AS numberOfPeopleBought
,sum(atbillfields.billeditemqty) AS soldquantity
FROM jtbillingtest.at_salesbill atsalesbill
JOIN jtbillingtest.at_billfields atbillfields
ON atsalesbill.billbatchguid=atbillfields.billbatchguid
WHERE atsalesbill.billcreationdate BETWEEN '2013-09-09' AND date_add('2013-09-09', INTERVAL 1 DAY)
GROUP BY atbillfields.billeditemguid) B ON B.billeditemguid = A.productguid
SET A.productQuantity = A.productQuantity - B.soldquantity
但是,得到以下异常:
Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe mode, toggle the option in Preferences -> SQL Queries and reconnect.
当我给 where
子句加上像 A.productQuantity = 1
这样的更新时,它更新了那个特定的。
有人可以指出为什么我无法执行查询以及如何解决这个问题吗?
最佳答案
看看:
如果你想在没有 where 键的情况下更新,你必须执行
SET SQL_SAFE_UPDATES=0;
就在您的查询之前。
另一种选择是重写您的查询或包含一个键。
关于mysql - 更新查询失败,错误为 : 1175,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18767308/