我在windows上的mysql客户端shell中运行了这个程序。我不明白问题出在哪里。我知道delete from PageInfo where id是对的。我知道子查询是正确的。我认为in是正确的,但我不经常使用它。整个过程看起来都是正确的,但我在某个地方遇到了问题。我不明白这个错误信息。
如何删除子查询返回的所有ids?
mysql> delete from PageInfo where id in ( select max(id) from PageInfo where pid
>=2758000 AND pid<2758100 group by pid having count(pid)>1 );
ERROR 1093 (HY000): You can't specify target table 'PageInfo' for update in FROM
clause发布于 2012-10-21 11:56:27
在MySQL中,您不能修改属于子查询的同一个表。
欲了解更多信息,请访问http://dev.mysql.com/doc/refman/5.6/en/update.html
发布于 2012-10-21 12:06:08
你可以这样做
delete from PageInfo where id = ( SELECT maxid FROM ( select max(id) as maxid from PageInfo where pid >=2758000 AND pid<2758100 group by pid having count(pid)>1) as tmp)发布于 2012-10-21 11:52:22
来自mysql website。如上所述,不允许从同一张表中选择和修改
在以下情况下会出现此错误:尝试修改表并从子查询中的同一个表中进行选择
Incorrectly used table in subquery:
Error 1093 (ER_UPDATE_TABLE_USED)
SQLSTATE = HY000
Message = "You can't specify target table 'x'
for update in FROM clause"
:https://stackoverflow.com/questions/12994768
复制相似问题