MySQL 报错 1093
[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
);