mySQL: delete 语句报错 You can't specify target table 'student' for update in FROM clause

delete from  student
where id NOT in (
select min(id) id from student group by name,stuid,subid,subname,score
);

当在mysql中执行这条语句时,报错:You can't specify target table 'student' for update in FROM clause;

原因是子查询中使用student表进行查询,而外层的delete语句也是对student进行的操作,因此报错。

解决办法:

将子查询再包装一次:

delete from  student
where id NOT in (
select * from (
select min(id) id from student group by name,stuid,subid,subname,score
)a
);

注意:这种错误只出现在mySQL中。

参考:http://blog.csdn.net/priestmoon/article/details/8016121

面朝大海,春暖花开。
原文地址:https://www.cnblogs.com/HapLe0/p/7761016.html