当前位置:Gxlcms > 数据库问题 > MySQL can’t specify target table for update in FROM clause

MySQL can’t specify target table for update in FROM clause

时间:2021-07-01 10:21:17 帮助过:1人阅读

   print?
  1. delete from t_official_sys_user  
  2. 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?
  1. [SQL]   
  2.   
  3. delete from t_official_sys_user  
  4. where USER_NAME IN(SELECT USER_NAME FROM t_official_sys_user b group by b.`USER_NAME` having  count(1) > 1)  
  5.   
  6. [Err] 1093 - You can‘t specify target table ‘t_official_sys_user‘ for update in FROM clause  



 

解决代码如下:

 

[sql] view plain copy    print?
  1. delete from t_official_sys_user  
  2. where USER_NAME IN(
  3. select USER_NAME from
  4.  ( 
  5. SELECT USER_NAME FROM t_official_sys_user b group by b.`USER_NAME` having  count(1) > 1
  6. as temtable 
  7. );  

分析:

先把要删除的目标放到一张临时表再把要删除的条件指定到这张临时表即可。

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

标签:

人气教程排行