mySQL: delete 语句报错 You can't specify target table 'student' for update in FROM clause(示例
Posted HapLe0
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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
以上是关于mySQL: delete 语句报错 You can't specify target table 'student' for update in FROM clause(示例的主要内容,如果未能解决你的问题,请参考以下文章
SQL语句报错:You have an error in your SQL syntax; check the manual that corresponds to your MariaDB serv
解决mysql8报错:ERROR 1410 (42000): You are not allowed to create a user with GRANT
mysql报unknown table in mulit delete错的原因和解决办法
mysql 5.7密码报错 ERROR 1820 (HY000): You must reset your password using ALTER USER statement before exe
MySQL sql 报错 You have an error in your SQL syntax; check the manual that corresponds to your MySQ
mysql - sql报错You can't specify target table 'table_name' for update in FROM clause