当前位置:Gxlcms > 数据库问题 > mySQL: delete 语句报错 You can't specify target table 'student' for update in FROM clause

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

时间:2021-07-01 10:21:17 帮助过:4人阅读

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

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

标签:sele   style   core   col   rom   语句   from   code   where   

人气教程排行