1

我正在尝试标记重复的事件 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
4

2 回答 2

2

当使用另一个子查询来掩盖您无法从正在更新的表中选择的情况时,您可以“欺骗”MySQL

update event 
set repeated = 1 
where eid in 
(
    select * from 
    (
        SELECT eid FROM event group by eid HAVING count(eid) > 1
    ) x
)
于 2013-06-18T18:09:19.503 回答
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
                 );
于 2013-06-18T18:09:25.683 回答