首页 > 代码库 > MySQL can’t specify target table for update in FROM clause
MySQL can’t specify target table for update in FROM clause
翻译:MySQL不能指定更新的目标表在FROM子句
源SQL语句:
[sql] view plain copy print?
- delete from t_official_sys_user
- where USER_NAME IN(SELECT USER_NAME FROM t_official_sys_user b group by b.`USER_NAME` having count(1) > 1)
执行报以下错误:
[sql] view plain copy print?
- [SQL]
- delete from t_official_sys_user
- where USER_NAME IN(SELECT USER_NAME FROM t_official_sys_user b group by b.`USER_NAME` having count(1) > 1)
- [Err] 1093 - You can‘t specify target table ‘t_official_sys_user‘ for update in FROM clause
解决代码如下:
[sql] view plain copy print?
- delete from t_official_sys_user
- where USER_NAME IN(
- select USER_NAME from
- (
- SELECT USER_NAME FROM t_official_sys_user b group by b.`USER_NAME` having count(1) > 1
- ) as temtable
- );
分析:
先把要删除的目标放到一张临时表再把要删除的条件指定到这张临时表即可。
http://blog.csdn.net/bluestarf/article/details/46622455
http://www.cnblogs.com/nick-huang/p/4412818.html
MySQL can’t specify target table for update in FROM clause
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。