问题:  

  今天在MySQL数据库删除重复数据的时候遇到了一个问题。如下脚本:

DELETE FROM tempA WHERE tid IN (
SELECT MAX(tid) AS tid FROM tempA GROUP BY name,age
)

  会出现报错信息:

  You can't specify target table 'tempA' for update in FROM clause

  大致意思是,在同一语句中,不能先select出同一表中的某些值,再update这个表。

解决方法:

  需要对上述脚本进行改造,如下:

DELETE FROM tempA WHERE tid NOT IN (
SELECT t.tid FROM (
SELECT MAX(tid) AS tid FROM tempA GROUP BY name,age
) t
)

  查询的时候增加一层中间表,就可以避免该错误。

错误:You can't specify target table 'xxx' for update in FROM clause的解决的更多相关文章

  1. mysql You can't specify target table 'xxx' for update in FROM clause的解决

    DELETE from sp_goodscontent where goodsId in (SELECT t.goodsId from ( SELECT goodsId FROM sp_goodsco ...

  2. You can't specify target table 'xxx' for update in FROM clause

    1.执行sql语句报上面的错误: DELETE FROM db_student WHERE RowGuid IN ( SELECT RowGuid FROM db_student WHERE age ...

  3. 关于mysql 5.7版本“报[Err] 1093 - You can't specify target table 'XXX' for update in FROM clause”错误的bug

    不同于oracle和sqlserver,mysql并不支持在更新某个表的数据时又查询了它,而查询的数据又做了更新的条件,因此我们需要使用如下的语句绕过: , notice_code ) a) ; 本地 ...

  4. mysql You can't specify target table 'xxx' for update in FROM clause

    含义:您不能在子句中为更新指定目标表'xxx'. 错误描述:删除语句中直接含select,如下: DELETE FROM meriadianannotation WHERE SeriesID IN ( ...

  5. django.db.utils.OperationalError: (1093, "You can't specify target table 'xxx' for update in FROM clause")

    这个错误的意思是,不能在update某张表的where条件中,再次select这张表的某些值作为筛选条件,比如: update message set content = "hello&qu ...

  6. mysql You can't specify target table 'sys_org_relation' for update in FROM clause 删除表条件不能直接包含该表

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

  7. MySQL中执行sql语句错误 Error Code: 1093. You can't specify target table 'car' for update in FROM clause

    MySQL中执行sql语句错误 Error Code: 1093. You can't specify target table 'car' for update in FROM clause 201 ...

  8. You can't specify target table 'a' for update in FROM clause

    项目中有一个功能变动上线,其中有一张表ttt的字段cc,历史数据需要处理,把字段cc中为'xxx'的值替换为'yyy'. 表A结构如下: CREATE TABLE `ttt` ( `id` bigin ...

  9. mysql中更新或者删除语句中子语句不能操作同一个表You can't specify target table 'test' for update in FROM clause

    问题描述:有个数据表test,有个字段value,如下 mysql> select * from test;+----+------------------------------------+ ...

随机推荐

  1. 【转载】HDFS 上传文件不均衡和Balancer太慢的问题

    向HDFS上传文件,如果是从某个datanode开始上传文件,会导致上传的数据优先写满当前datanode的磁盘,这对于运行分布式程序是非常不利的. 解决的办法: 1.从其他非datanode节点上传 ...

  2. [转载]mysql中实现行号,oracle中的rowid

    mysql中实现行号需要用到MYSQL的变量,因为MySql木有rownumber. MYSQL中变量定义可以用 set @var=0 或 set @var:=0 可以用=或:=都可以,但是如果变量用 ...

  3. Django之cookie验证

    先不用太多的蚊子描述什么是cookie,先做一个小实验: 此时我们在谷歌浏览器(一个客户端)和IE浏览器(另一个用户)测试: 刺客我们发现在两台浏览器都可以访问,而且不用进入login验证就可以登录, ...

  4. Arch Linux安装记录

    1.分区(MBR)# cfdisk 半图形界面,划分三个区:sda1 20G,sda2 80G,sda3 4G. 2.创建文件系统# mkfs.ext4 /dev/sda1# mkfs.ext4 /d ...

  5. 使用python写天气预告

    先去YY天气注册一个账号,然后就能用API了 http://www.yytianqi.com/ # encoding=utf-8import urllib.requestimport jsonimpo ...

  6. Codeforces 777C Alyona and Spreadsheet

    C. Alyona and Spreadsheet time limit per test:1 second memory limit per test:256 megabytes input:sta ...

  7. hihoCoder1498-Diligent Robots

    #1498 : Diligent Robots Time Limit:10000ms Case Time Limit:1000ms Memory Limit:256MB Description The ...

  8. A. Duff and Meat

    A. Duff and Meat time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  9. oracle 11g体系结构

    1.数据库体系结构 1.1 数据库和实例的关系database server  = instance 实例 + database 数据库instance 实例  =内存 memory + 进程  pr ...

  10. yum指令

    接上个教程,如果用yum list 命名,运行后出现如下结果:则正确搭建了环境 如 yum search httpd 搜索apache的包 安装gcc ,是c语言的编译器 注意:LANG是临时改变的. ...