我正在尝试删除表中除具有最大值 revision_id
的行之外的所有行value同时从同一个表中选择数据:
delete from
node_revision__body
where
entity_id=4
and revision_id not in (
select
max(revision_id)
from
node_revision__body
where
entity_id=4
)
这会引发错误
You can't specify target table 'node_revision__body' for update in FROM clause
是否可以以某种方式更改查询以实现目标?
最佳答案
这是一个documented MySql 的“功能”,您无法更新您选择的同一个表,但是存在一些解决方法,例如您可以尝试将查询嵌套更深一层:
delete from node_revision__body
where entity_id = 4
and revision_id not in (
select revision_id from (
select max(revision_id) revision_id
from node_revision__body
where entity_id = 4
)b
);
关于mysql - 如何同时从同一个表中选择从 SQL 表中删除行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74762297/