mysql中You can't specify target table for update in FROM clause
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql中You can't specify target table for update in FROM clause相关的知识,希望对你有一定的参考价值。
使用mysql在删除表中重复记录
delete from user where username in (select user name form(select username from user group by username having count(username)>1));
遇到mysql报错You can‘t specify target table for update in FROM clause
上网百度了下原来是mysql中不允许先select出同一表中的某些值,再update这个表(在同一语句中),这个问题只出现于mysql,sqlserver和oracle不会出现此问题
解决办法:将select出的结果再通过中间表select一遍
delete from user where username in (select a.username from(select username from user group by username having count(username)>1)a);
这样delete和select的就不是同一个表了
以上是关于mysql中You can't specify target table for update in FROM clause的主要内容,如果未能解决你的问题,请参考以下文章
mysql中You can't specify target table for update in FROM clause错误
MySQL 中 You can't specify target table '表名' for update in FROM clause错误解决办法
MySQL中You can't specify target table for update in FROM clause一场
mySQL: delete 语句报错 You can't specify target table 'student' for update in FROM clause(示例
MySQL之You can't specify target table for update FROM clause解决办法
mysql error:You can't specify target table for update in FROM clause