You can't specify target table 'scores' for update in FROM clause

在mysql中使用:
DELETE FROM scores WHERE id not in ( SELECT min(id) GROUP BY name,score,subject);

报错:

You can't specify target table 'scores' for update in FROM clause
这是mysql才有的错误。
替代:
create table tmp as select min(id) as col from scores group by name,score,subject;
delete from scores where id not in (select col from tmp); 
DROP TABLE tmp;
参考:https://zhidao.baidu.com/question/68619324.html

猜你喜欢

转载自blog.csdn.net/mysevenyear/article/details/80526297