gpt4 book ai didi

mysql - 错误 1093 (HY000) : You can't specify target table 'a' for update in FROM clause

转载 作者:行者123 更新时间:2023-11-29 02:02:02 25 4
gpt4 key购买 nike

我有这个问题

UPDATE trh_adminLoginDate SET superseded = true WHERE EXISTS 
(SELECT * FROM trh_adminLoginDate AS a2 WHERE a2.adminId = a.adminId AND a2.loginDate > a.loginDate AND a2.clientPlatform = a.clientPlatform)

表格看起来像这样。

+----------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------------+--------------+------+-----+---------+----------------+
| id | bigint(20) | NO | PRI | NULL | auto_increment |
| dateCreated | datetime | NO | | NULL | |
| version | int(11) | NO | | NULL | |
| dateModified | datetime | NO | | NULL | |
| adminId | bigint(20) | NO | MUL | NULL | |
| clientPlatform | varchar(255) | YES | | NULL | |
| loginDate | datetime | YES | | NULL | |
| superseded | tinyint(1) | NO | | NULL | |
+----------------+--------------+------+-----+---------+----------------+

当我执行此查询时,出现以下错误:

ERROR 1093 (HY000): You can't specify target table 'a' for update in FROM clause

我可以创建临时表并保留子查询的结果,然后执行更新。但我不想这样做。有人可以建议我更好的方法吗?

最佳答案

您正在使用别名“a”,但您从未定义它。

也许这会起作用:

UPDATE  trh_adminLoginDate a

JOIN trh_adminLoginDate AS a2
ON a2.adminId = a.adminId
AND a2.loginDate > a.loginDate
AND a2.clientPlatform = a.clientPlatform

SET a.superseded = true

关于mysql - 错误 1093 (HY000) : You can't specify target table 'a' for update in FROM clause,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13188002/

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