首页 > 代码库 > 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 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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。