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. 《阿里巴巴Java开发手册》码出高效详解(一)- 为什么要学习阿里编码手册

    <Java 开发手册>(以下简称<手册>)是每个 Java 工程师人手必备的一本参考指南.该手册包括 编程规约.异常日志.单元测试.安全规约.MySQL 数据库.工程结构.设计 ...

  2. Redis(八):zset/zadd/zrange/zrembyscore 命令源码解析

    前面几篇文章,我们完全领略了redis的string,hash,list,set数据类型的实现方法,相信对redis已经不再神秘. 本篇我们将介绍redis的最后一种数据类型: zset 的相关实现. ...

  3. HanLP《自然语言处理入门》笔记--2.词典分词

    2. 词典分词 中文分词:指的是将一段文本拆分为一系列单词的过程,这些单词顺序拼接后等于原文本. 中文分词算法大致分为基于词典规则与基于机器学习这两大派. 2.1 什么是词 在基于词典的中文分词中,词 ...

  4. Spring IoC 容器和 bean 对象

    程序的耦合性: 耦合性(Coupling),又叫耦合度,是对模块间关联程度的度量.耦合的强弱取决于模块间接口的复杂性.调用模块的方式以及通过界面传送数据的多少.模块间的耦合度是指模块之间的依赖关系,包 ...

  5. openstack中的延迟删除

    glance镜像的延迟删除 在控制节点的glance-api.conf文件中设置延迟删除: # Turn on/off delayed delete delayed_delete = False # ...

  6. solaris系统磁盘镜像

    查看磁盘分区 查看系统的磁盘数据与容量: 用format查看一下磁盘的情况,0号盘是c1t0d0,系统源磁盘,1号盘是c1t1d0,新增加磁盘,作为镜像盘使用. 注意:两块硬盘的容量最好相等,如果镜像 ...

  7. CCF_201409-1_相邻数对

    水. #include<iostream> #include<cstdio> #include<algorithm> using namespace std; in ...

  8. SSH: ssh隧道

    简介 Secure Shell(安全外壳协议,简称SSH)是一种加密的网络传输协议,可在不安全的网络中为网络服务提供安全的传输环境.SSH通过在网络中创建安全隧道来实现SSH客户端与服务器之间的连接. ...

  9. Thread Based Parallelism - Thread in a Subclass

    Thread Based Parallelism - Thread in a Subclass 1 import threading import time exit_Flag = 0 class m ...

  10. JVM解毒——类加载子系统

    带着问题,尤其是面试问题的学习才是最高效的.加油,奥利给! 点赞+收藏 就学会系列,文章收录在 GitHub JavaEgg ,N线互联网开发必备技能兵器谱 直击面试 看你简历写得熟悉JVM,那你说说 ...