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这个表( ...
随机推荐
- idea实现svn拉分支和合并分支的教程
原文地址:https://blog.csdn.net/qq_27471405/article/details/78498260 今天测试了一下svn拉分支和合并分支的教程,决定分享给大家 拉分支教程: ...
- selenium + PhantomJS使用时 PhantomJS报错解决
selenium + PhantomJS使用时 PhantomJS报错解决 在做动态网页爬虫时用到了selenium + PhantomJS,安装好之后运行时报错: UserWarning: Sele ...
- IdentityServer4身份认证授权入门
一.简介 IdentityServer4 是为ASP.NET Core 系列量身打造的一款基于 OpenID Connect 和 OAuth 2.0 认证框架 特点: 1.认证服务 2.单点登录登出( ...
- 多线程之CountDownLatch的用法及原理笔记
前言-CountDownLatch是什么? CountDownLatch是具有synchronized机制的一个工具,目的是让一个或者多个线程等待,直到其他线程的一系列操作完成. CountDownL ...
- Linux学习笔记-Centos7搭建owncloud私有云盘
使用环境:虚拟机centos7 1.下载安装LAMP相关软件 [root@localhost yum.repos.d]# yum install httpd –y [root@localhost yu ...
- 原生Ajax发送get、post请求每一步
说明 发送Ajax的请求的核心对象是XMLHttpRequest,因此我们需要了解该对象的相关属性和方法 方法(图一) 属性(图二) 第一步:创建 XMLHttpRequest对象,下面都简写为 xh ...
- mybatis缓存,从一个“灵异”事件说起
刚准备下班走人,被一开发同事叫住,让帮看一个比较奇怪的问题:Mybatis同一个Mapper接口的查询方法,第一次返回与第二次返回结果不一样,百思不得其解! 问题 Talk is cheap. Sho ...
- 【5min+】 这些C#的运算符您都认识吗?
系列介绍 [五分钟的dotnet]是一个利用您的碎片化时间来学习和丰富.net知识的博文系列.它所包含了.net体系中可能会涉及到的方方面面,比如C#的小细节,AspnetCore,微服务中的.net ...
- Java实现多线程下载,支持断点续传
完整代码:https://github.com/iyuanyb/Downloader 多线程下载及断点续传的实现是使用 HTTP/1.1 引入的 Range 请求参数,可以访问Web资源的指定区间的内 ...
- C语言宏的神奇写法:语句块作为参数,算半个函数式编程?
我想要写几个循环做测试代码,每次都写 `for(size_t i = 0; i < n; i++)` 很烦人,然后就灵机一动,能不能用宏实现,然后就写出了: #define repeat(n, ...