翻译:MySQL不能指定更新的目标表在FROM子句

源SQL语句:

  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)

执行报以下错误:

  1. [SQL]
  2. delete from t_official_sys_user
  3. where USER_NAME IN(SELECT USER_NAME FROM t_official_sys_user b group by b.`USER_NAME` having  count(1) > 1)
  4. [Err] 1093 - You can't specify target table 't_official_sys_user' for update in FROM clause

解决代码如下:

  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的更多相关文章

  1. mysql中You can’t specify target table for update in FROM clause错误解决方法

    mysql中You can't specify target table for update in FROM clause错误的意思是说,不能先select出同一表中的某些值,再update这个表( ...

  2. mysql 一个较特殊的问题:You can't specify target table for update in FROM clause

    mysql 一个较特殊的问题:You can't specify target table for update in FROM clause 即:不能先select出同一表中的某些值,再update ...

  3. 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 ...

  4. 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 c ...

  5. MySQL 出现You can't specify target table for update in FROM clause错误解决方法

    MySQL出现You can’t specify target table for update in FROM clause 这个错误的意思是不能在同一个sql语句中,先select同一个表的某些值 ...

  6. MYSQL 1093 之You can't specify target table for update in FROM clause解决办法

    You can't specify target table for update in FROM clause含义:不能在同一表中查询的数据作为同一表的更新数据. 出现以上错误,是因为想将表自身的字 ...

  7. MYSQL之You can't specify target table for update in FROM clause解决办法

    mysql中You can't specify target table for update in FROM clause错误的意思是说,不能先select出同一表中的某些值,再update这个表( ...

  8. mysql error:You can't specify target table for update in FROM clause

    mysql中You can't specify target table for update in FROM clause错误的意思是说,不能先select出同一表中的某些值,再update这个表( ...

  9. Mysql中You can't specify target table for update in FROM clause错误的意思是说,不能先select出同一表中的某些值,再update这个表(在同一语句中)。

    将select出的结果再通过中间表select一遍,这样就规避了错误.注意,这个问题只出现于mysql,mssql和oracle不会出现此问题. mysql中You can't specify tar ...

随机推荐

  1. C#下如何用NPlot绘制期货股票K线图(1)?

    [简介] 作为一名专业程序化交易者,编程是一个程序员的基本功,本文是作者在做的一个期货CTP项目中有关K线绘图的一部分,偿试类MT4中图表 设计而写,在编写绘图时,查阅了相关资料,感觉还是用NPlot ...

  2. 07_XPath_02_常用语法

    [工程截图] [person.xml] <?xml version="1.0" encoding="UTF-8"?> <students> ...

  3. CAF(C++ actor framework)使用随笔(send sync_send)(二)

    a). 发完就忘, 就像上面anon_send 以及send #include <iostream> #include "caf/all.hpp" #include & ...

  4. 九度OJ1198 a+b 【高精度整数】

    题目地址:http://ac.jobdu.com/problem.php?pid=1198 题目描述: 实现一个加法器,使其能够输出a+b的值. 输入: 输入包括两个数a和b,其中a和b的位数不超过1 ...

  5. 第32条:用EnumSet代替位域

    如果一个枚举类型的元素主要用在集合中,一般使用int枚举模式,将2的不同倍数赋予每个常量: public class Text { public static final int STYLE_BOLD ...

  6. 《APUE》第四章笔记(2)

    下面介绍对stat结构的各个成员的操作函数. 先贴个stat结构的图: access函数: #include <unistd.h> int access(const char *pathn ...

  7. read/write数据读写传输方式(转)

    前言 笔者本打算撰写一篇讲解标准I/O(缓存I/O)的博文,但是发现已经有网友做过同样的工作,并且工作质量上乘,特转载于此. 原文地址http://lenky.info/archives/2012/0 ...

  8. jQuery中模拟用户操作

    有时为了节省不想手动操作网页,但又想看到用户操作时的效果,可以用到jQuery提供的trigger方法.见下图代码 在不点击按钮时仍然想弹出this.value 我们只需要在后面加上.trigger( ...

  9. springdata整合mongodb一些方法包括or,and,regex等等《有待更新》

    这几天接触mongodb以及springdata,自己英语比较戳,所以整理这些方法花的时间多了点,不过也是我第一次在外国网站整理技术 不多说,直接上代码,这里只是给出一些操作方法而已,如果有需要源码的 ...

  10. PHP常见算法-面试篇(2)

    1.顺序查找 思路分析: 从数组的第一个元素开始一个一个向下查找,如果有和目标一致的元素,查找成功:如果到最后一个元素仍没有目标元素,则查找失败. 代码实现: <?php function se ...