![](/img/trans.png)
[英]MySQL safe mode error even when using the primary key in a where clause
[英]Error when updating from select on same table EVEN when using primary key in WHERE clause
那是我的查詢:
UPDATE status as t1
JOIN (
SELECT status.id, status.deployment_id FROM status
) as t2
SET t1.task_id=t2.deployment_id
WHERE t1.id=t2.id;
這就是響應:
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.
但是我實際上在查詢中使用了主鍵,為什么我仍然得到這樣的結果?
PS
我使用MySQL。
我的猜測是問題是子查詢,不需要。 您可以這樣寫:
UPDATE status as t1 JOIN
status t2
ON t1.id = t2.id
SET t1.task_id = t2.deployment_id;
當然,如果id
是主鍵,那么它是唯一的,並且永遠不會為NULL
,因此編寫起來要簡單得多:
UPDATE status s
SET s.task_id = s.deployment_id;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.