mysql - delete from where id in subquery 错误

标签 mysql syntax-error

我在 Windows 上的 mysql 客户端 shell 中运行了它。我不明白问题出在哪里。我知道 从 PageInfo 中删除 id 是正确的。我知道子查询是正确的。我认为 in 是正确的,但我不经常使用它。这整件事看起来是正确的,但我在某个地方遇到了问题。我不明白错误信息。

如何删除子查询返回的所有 ID?

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

最佳答案

你可以这样做

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)

关于mysql - delete from where id in subquery 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12994768/

相关文章:

mysql - 使用 Datagridview 中的复选框列重复一个过程

php - 如何在 laravel DB::select 查询中使用分页

python - 如何更正 TypeError : Unicode-objects must be encoded before hashing?

java - 在 Java 中创建一个二维对象数组

php - 如何插入没有任何值的行,以便所有列都采用默认值?

mysql - 当查询中未使用字段时,MySQL InnoDB 表中文本字段的大小会影响性能吗

php - 从 Google Chart 时间线项目创建链接

php - PHP解析/语法错误;以及如何解决它们

php - 解析错误 : syntax error, 意外的 T_IF

c - Java-Python 翻译器中求和运算的语法问题