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这个表( ...
随机推荐
- Python赋值没有返回值+笔试
>>> def test(): i = 1 return i=2 SyntaxError: invalid syntax 原因是python 中赋值语句没有返回值,这里不是C++
- 添加动态输出 Adding Dynamic Output 精通ASP-NET-MVC-5-弗瑞曼 Listing 2-7
ViewBag Dynamic Output
- selenium,测试套件的使用
学习 selenium-webdriver 已经一段时间了,最近学习到,测试用例的批量执行,和测试套件的使用,有点自己的理解,不晓得对不对,希望大家指正! 写一个测试用例 baidu.py c ...
- Mybatis基础(一)
mybatis概述: MyBatis 是一款优秀的持久层框架,它支持定制化 SQL.存储过程以及高级映射.MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集.MyBatis ...
- Spring-Cloud之Eureka注册中心环境搭建(单节点)
一 Eureka概述 服务启动时会生成服务的基本信息对象InstanceInfo,然后在启动时会register到服务治理中心. 注册完成后会从服务治理中心拉取所有的服务信息,缓存在本地. 之后服务会 ...
- springBoot 启动没有数据库配置报错
在没有配置数据库的时候, 直接启动springBoot 项目 会有报错 Description: Failed to configure a DataSource: 'url' attribute i ...
- 终于知道为什么linux文件系统权限是124了
哈哈,恍然大悟,出自pythonweb开发实战这一本书135页,有兴趣的朋友可以去了解下!
- Java8新特性一点通 | 回顾字符转日期&JoinArray使用
StringToDate日期转换 Join Array使用 StringToDate日期转换 Convert string to date in ISO8601 format 利用LocalDate. ...
- CSS-- 实用CSS样式
自用实用CSS样式 1.清除DIV浮动 <span style="font-family:KaiTi_GB2312;">clear: both;</span> ...
- 1759: 学生信息插入(武汉科技大学结构体oj)(已AC)
#include<stdio.h>struct student { long no; char name[9]; int score;} t;void input(struct stude ...