gpt4 book ai didi

MySQL错误: You can't specify target table 'users_words' for update in FROM clause

转载 作者:行者123 更新时间:2023-11-29 08:01:07 28 4
gpt4 key购买 nike

请看一下我的 MySQL 子句。

UPDATE `users_words` SET `priority` = (SELECT MAX(`priority`)+1 FROM `users_words`) where `userid` = 89 AND `wordid`="agree"

这里我要更新priority字段的现有最大值 priority 加 1字段值。但我收到错误 You can't specify target table 'users_words' for update in FROM clause .

如何解决这个问题?

最佳答案

只需将子查询包装在另一个 SELECT 中:

UPDATE `users_words` 
SET `priority` = (SELECT x.* FROM (SELECT MAX(`priority`)+1 FROM `users_words`) x)
WHERE `userid` = 89 AND `wordid`="agree"

关于MySQL错误: You can't specify target table 'users_words' for update in FROM clause,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23770598/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com