update mysql row (You can't specify target table 'x' for update in FROM clause)
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)的更多相关文章
- 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 ...
- 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) ...
- 解决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) 解决方法 ...
- mysql:You can't specify target table 'sessions' for update in FROM clause
更新数据时,在where条件子句里面如果想使用子查询按条件更新部分数据,需要将查询的结果设为临时表.可以参考: https://blog.csdn.net/poetssociety/article/d ...
- 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出同一表中的某些值 ...
- 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出同一表中的某些值 ...
- 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 ...
- mysql中更新或者删除语句中子语句不能操作同一个表You can't specify target table 'test' for update in FROM clause
问题描述:有个数据表test,有个字段value,如下 mysql> select * from test;+----+------------------------------------+ ...
- 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这个表( ...
随机推荐
- Dappy如何防止DNS黑客入侵
作者:Raphaël 译者注:Dappy是RChain生态中的DNS[域名系统(服务)协议].Dappy基于RChain的技术架构保障了域名系统的安全性. Dappy是一个用于文件和Web应用程序的去 ...
- 对于kvm配置ssh
首先我们要让自己的机器开启ssh服务 首先更新源 sudo apt-get update 安装ssh服务 sudo apt-get install openssh-server 检测是否已启动 ps ...
- c#移位运算符("<<"及">>")
C#是用<<(左移) 和 >>(右移) 运算符是用来执行移位运算. 左移 (<<) 将第一个操作数向左移动第二个操作数指定的位数,空出的位置补0. 左移相当于乘. ...
- [ Python入门教程 ] Python中日期时间datetime模块使用实例
Python中datetime模块提供强大易用的日期处理功能,用于记录程序操作或修改时间.时间计算.日志时间显示等功能.datatime模块重新封装了time模块,提供的类包括date.time.da ...
- Docker在树莓派的安装与使用(Ubuntu Arm Server v19.10)
最近由于冠状病毒疫情的原因,只能够和小朋友家里蹲.这几天把尘封已久的那个树莓派拿出来继续捣鼓.希望能够做一个异构的分布式系统框架,于是想把Docker也安装到树莓派上,以便后期做进一步的开发和实验. ...
- 将Ubuntu下网卡名称enss改为eth0
将Ubuntu下网卡名称enss改为eth0 sudo nano /etc/default/grub 找到GRUB_CMDLINE_LINUX=""改为GRUB_CMDLINE ...
- tomcat+jenkins搭建持续化集成环境
一.下载安装Tomcat 1.进入官网http://tomcat.apache.org/ 2.解压缩文件到指定目录 3.设置环境变量 a.新建CATALINA_HOME b.在path中设置 %CAT ...
- 【学习笔记】Git的日常使用
Note:本笔记是我学习廖雪峰老师的Git教程整理得到,在此向廖老师的无私付出表示衷心的感谢! 0.Git的历史 Git是一个分布式的版本控制系统(C语言编写,一开始为Linux社区服务,替代BitK ...
- Spring基于注解配置AOP
D:\Java\IdeaProjects\JavaProj\SpringHelloWorld\src\aop.xml <?xml version="1.0" encoding ...
- rep stos 指令(Intel汇编)
今天读代码时,忽然跳出如下一条指令==>> 汇编代码: rep stos dword ptr es:[edi] 在网上查了相关资料显示: /************************ ...