mysql 根据 select 语句从同一个 table 中删除

mysql delete from same table based on select statement

我真是绕轴了
我正在尝试从 table.
中删除一些记录 这行不通...

delete from table where id in (select id from table where ...

...因为我得到了可怕的...

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

...所以我选择了临时 table 选项 ...

create temporary table idTemp (idt bigint(20) unsigned); insert into idTemp select id from table where [...]; delete from table where id in (select idt from idTemp); drop table idTemp;

... 仅当 运行 作为 root 时才有效。如果我 运行 作为所需的用户,无论我给用户多少权限,我都会被拒绝访问。
我尝试添加 CREATE、DROP、INSERT、DELETE,SELECT,但仍然无法访问。
但是当我尝试为用户提供 CREATE TEMPORARY TABLES 访问权限时,我得到 ...

ERROR 1144 (42000): Illegal GRANT/REVOKE command

我在 Linux.MySQL 上安装了 MySQL 版本 5.5.14 运行ning 任何帮助将不胜感激!

mysql>

GRANT ALL ON *.* TO 'someuser'@'somehost';
GRANT SELECT, INSERT ON *.* TO 'someuser'@'somehost';

您还可以将您的原始查询表述为 join:

DELETE t
FROM table t
JOIN (SELECT id FROM table WHERE ...) todelete ON t.id = todelete.id