sql语句(update/delete都会出现此问题)

update x set available_material_id = null where id not in (select id from x where additional_info = 1);

mistake

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

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

mysql5.7解决办法

update x left join
x xx
on x.id = xx.id and xx.additional_info = 1
set available_material_id = null
where xx.id is null;

老办法(有人说5.7已经不能用了)

原始:

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

改造后

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

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

参考

https://stackoverflow.com/questions/51087937/on-update-mysql-row-you-cant-specify-target-table-x-for-update-in-from-claus
https://blog.csdn.net/h996666/article/details/81699255
https://stackoverflow.com/questions/4429319/you-cant-specify-target-table-for-update-in-from-clause/14302701
https://www.cnblogs.com/pcheng/p/4950383.html
https://blog.csdn.net/poetssociety/article/details/82391523

update mysql row (You can't specify target table 'x' for update in FROM clause)的更多相关文章

  1. MySQL 1093 - You can't specify target table 'sc' for update in FROM clause

    错误代码如下: #(8) 把"邓维杰"同学的成绩全部删除. SELECT * FROM sc WHERE EXISTS(SELECT * FROM student WHERE st ...

  2. mysql:You can't specify target table 'bpm_tksign_data' for update in FROM clause

    UPDATE bpm_tksign_data WHERE actinstid ' AND nodeid = 'SignTask1' AND batch = ( SELECT max(a.batch) ...

  3. 解决MYSQL的You can't specify target table 'xxxxxxxxxx' for update in FROM clause

    出现这个问题的MYSQL的SQL语句形如: DELETE FROM xxxxa WHERE EXISTS (SELECT * FROM xxxx1 WHERE xxxxa.xxid=123) 解决方法 ...

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

    更新数据时,在where条件子句里面如果想使用子查询按条件更新部分数据,需要将查询的结果设为临时表.可以参考: https://blog.csdn.net/poetssociety/article/d ...

  5. MySQL中You can't specify target table for update in FROM clause一场

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

  6. MySQL中You can't specify target table for update in FROM clause异常

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

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

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

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

  9. 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这个表( ...

随机推荐

  1. fastjson中Map与JSONObject互换

    1.//将map转换成jsonObject JSONObject itemJSONObj = JSONObject.parseObject(JSON.toJSONString(itemMap)); 将 ...

  2. HCNA 2017年01月26日

    [Huawei]ping 127.0.0.1 PING 127.0.0.1: 56 data bytes, press CTRL_C to break Reply from 127.0.0.1: by ...

  3. [CF1192B]动态直径

    题意 给一棵固定形态的树,边有边权,每次修改一条边权,在线求出修改后树的直径. 思考 写出树的全dfs序.生成方式为:每当一个点进栈或入栈时,记录它的编号. 考虑这个dfs序上两点之间的距离.设某个节 ...

  4. 尼姆博弈+SG函数

    博弈这个东西真的很费脑诶.. 尼姆博奕(Nim Game):游戏者轮流从一堆棋子(或者任何道具)中取走一个或者多个,最后不能再取的就是输家.当指定相应数量时,一堆这样的棋子称作一个尼姆堆 当n堆棋子的 ...

  5. Git详解之分支使用

    前言 几乎每一种版本控制系统都以某种形式支持分支.使用分支意味着你可以从开发主线上分离开来,然后在不影响主线的同时继续工作.在很多版本控制系统中,这是个昂贵的过程,常常需要创建一个源代码目录的完整副本 ...

  6. Nginx(3)---代理与负载均衡

    一.代理简述 代理分为正向代理和反向代理, 正向代理:客户端与目标服务器之间增加一个代理服务器,客户端直接访问代理服务器,在由代理服务器访问目标服务器并返回客户端并返回 .比如夜深人静的时候访问的一些 ...

  7. TCP UDP协议的三次握手

    接触网络协议栈TCP/IP的人,就一定绕不开的一个话题就是TCP的三次握手.下面我将简单介绍一下. 三次握手流程的本质,可以这么理解:TCP的三次握手其实是双方各一次握手,各一次确认,只是其中一次握手 ...

  8. Java数据类型及对应取值范围

    Java数据类型及对应取值范围 在Java中,数据类型分为两大种:基本数据类型(值类型)和包装类型(引用数据类型).基本数据类型不是对象,不能调用toString().hashCode().getCl ...

  9. Jumpserver:跳板机

    简介 jumpserver是github上的一个开源项目,其能有效的对服务器.用户进行分组,实现用户-系统用户-服务器的对应权限控制,并结合审计.日志等功能,据说是 4A 级的专业运维审计系统,系统提 ...

  10. Spring Cloud(六):服务网关zuul

    通过前面几篇文章的介绍,Spring Cloud微服务架构可通过Eureka实现服务注册与发现,通过Ribbon或Feign来实现服务间的负载均衡调用,通过Hystrix来为服务调用提供服务降级.熔断 ...