我正在尝试标记重复的事件ID。
update event set repeated = 1 where eid in
(SELECT eid FROM event group by eid HAVING count(eid) > 1);
但是,我收到以下回复:
You can't specify target table 'event' for update in FROM clause
答案 0 :(得分:2)
当使用另一个子查询来覆盖那些你无法从正在更新的表中选择时,你可以“欺骗”MySQL
update event
set repeated = 1
where eid in
(
select * from
(
SELECT eid FROM event group by eid HAVING count(eid) > 1
) x
)
答案 1 :(得分:1)
这是MySQL的缺点之一。您可以通过将子查询包装在另一个子查询中来修复它:
update event
set repeated = 1
where eid in (select eid
from (SELECT eid
FROM event
group by eid
HAVING count(eid) > 1
) t
);