MySQL #1093 - 您无法指定目标表“赠品”;用于 FROM 子句中的更新
我尝试过:
UPDATE giveaways SET winner = '1' WHERE ID = (SELECT MAX(ID) FROM giveaways)
但它给出了:
#1093 - 您无法在
FROM
子句中指定要更新的目标表“赠品”
这篇文章 似乎相关,但我无法使其适应我的查询。我怎样才能让它发挥作用?
I tried:
UPDATE giveaways SET winner = '1' WHERE ID = (SELECT MAX(ID) FROM giveaways)
But it gives:
#1093 - You can't specify target table 'giveaways' for update in
FROM
clause
This article seems relevant but I can't adapt it to my query. How can I get it to work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
根据您链接到的文章中的信息,这应该有效:
Based on the information in the article you linked to this should work:
这是因为您的更新可能是周期性的...如果更新该记录导致发生导致
WHERE
条件FALSE
的情况怎么办?您知道情况并非如此,但引擎却不然。操作中表上也可能存在相反的锁。我认为你可以这样做(未经测试):
了解更多
This is because your update could be cyclical... what if updating that record causes something to happen which made the
WHERE
conditionFALSE
? You know that isn't the case, but the engine doesn't. There also could be opposing locks on the table in the operation.I would think you could do it like this (untested):
Read more
使用 TEMP TABLE:
如下:
Make use of TEMP TABLE:
as follows:
您可以先创建子查询的视图,然后更新/删除从视图中选择。
只需记住之后删除视图即可。
You can create a view of the subquery first and update/delete selecting from the view instead..
Just remember to drop the view after.