[Err] 1093 - You can't specify target table 'user' for update in FROM clause
報錯的sql如下:
delete from `user` where id not in (select min(id) as id from `user` group by name );
報錯的原因是:不能先select出同一表中的某些值,再update這個表(在同一語句中)。
改成下面這樣就好了(將查出的數據再通過中間表查一遍):
delete from `user` where id not in (
select id from(
select min(id) as id from `user` group by name
) id
);