码迷,mamicode.com
首页 > 数据库 > 详细

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

时间:2017-10-31 14:10:06      阅读:188      评论:0      收藏:0      [点我收藏+]

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

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

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

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

原文地址:http://www.cnblogs.com/HapLe0/p/7761016.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!