mysql - 更新查询失败,错误为 : 1175

标签 mysql sql

我正在尝试使用以下查询更新表

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 这样的更新时,它更新了那个特定的。

有人可以指出为什么我无法执行查询以及如何解决这个问题吗?

最佳答案

看看:

http://justalittlebrain.wordpress.com/2010/09/15/you-are-using-safe-update-mode-and-you-tried-to-update-a-table-without-a-where-that-uses-a-key-column/

如果你想在没有 where 键的情况下更新,你必须执行

SET SQL_SAFE_UPDATES=0;

就在您的查询之前。

另一种选择是重写您的查询或包含一个键。

关于mysql - 更新查询失败,错误为 : 1175,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18767308/

相关文章:

python - pyodbc - 如何使用变量作为参数执行 select 语句

sql - 条件连接 - 动态 SQL

sql - 在数据库中查找最接近的数值

mysql - 尝试切换到导入到 MySQL 时出现转储文件错误

sql - 将条件计数分段到相同的 'virtual' 列

php - COUNT(*) AS 出现次数,php 如何捕获每次出现的值

php - 无法重定向到 MainActivity 屏幕

mysql - 在vb6中存储带空格的句子

mysql - 获取MySQL中每个组的top-k

java - 出现不正确的 SQL 语法