You can't specify target table 'ship_product_cat' for update in FROM clause
有时候我们在编辑update时需要select作为条件,在mysql中有时会出现这样的错误:You can't specify target table for update in FROM clause错误的意思是说,不能先select出同一表中的某些值,再update这个表(在同一语句中)。
例如下面这个sql:
UPDATE ship_product_cat SET is_parent = 0 WHERE id in(
SELECT id FROM ship_product_cat WHERE name in('Control','Propeller/Shaft')
);
错误信息:
| [SQL]UPDATE ship_product_cat SET is_parent = 0 WHERE id in( SELECT id FROM ship_product_cat WHERE name in('Control','Propeller/Shaft')); [Err] 1093 - You can't specify target table 'ship_product_cat' for update in FROM clause |
解决方法——换成下面的SQL就可以了
UPDATE ship_product_cat SET is_parent = 0 WHERE id in(
SELECT a.id FROM
(SELECT id FROM ship_product_cat WHERE name in('Control','Propeller/Shaft'))a
);
也就是说将select出的结果再通过中间表select一遍,这样就规避了错误。
这个错误会出现在mysql中,但不会出现在oracle中。
You can't specify target table 'ship_product_cat' for update in FROM clause的更多相关文章
- 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 'cpn_regist' for update in FROM clause
今天在操作数据库的时候遇到了一个问题,sql语句如下: UPDATE cpn_yogurt_registration SET dep1Name = '1' WHERE `key` in (SELEC ...
- Mysql update in报错 [Err] 1093 - You can't specify target table 'company_info' for update in FROM clause
Mysql update in报错 解决方案: [Err] 1093 - You can't specify target table 'company_info' for update in FRO ...
- 错误:You can't specify target table 'xxx' for update in FROM clause的解决
问题: 今天在MySQL数据库删除重复数据的时候遇到了一个问题.如下脚本: DELETE FROM tempA WHERE tid IN ( SELECT MAX(tid) AS tid FROM t ...
- [Err] 1093 - You can't specify target table 's' for update in FROM clause
[Err] 1093 - You can't specify target table 's' for update in FROM clause 执行SQL DELETE from book WHE ...
- 【MySQL】解决You can't specify target table 'user_cut_record_0413' for update in FROM clause
问题 You can't specify target table 'user_cut_record_0413' for update in FROM clause 原因 待更新/删除的数据集与查询的 ...
- MySQL中执行sql语句错误 Error Code: 1093. You can't specify target table 'car' for update in FROM clause
MySQL中执行sql语句错误 Error Code: 1093. You can't specify target table 'car' for update in FROM clause 201 ...
- 关于mysql 5.7版本“报[Err] 1093 - You can't specify target table 'XXX' for update in FROM clause”错误的bug
不同于oracle和sqlserver,mysql并不支持在更新某个表的数据时又查询了它,而查询的数据又做了更新的条件,因此我们需要使用如下的语句绕过: , notice_code ) a) ; 本地 ...
- MySQL - 1093异常 - You can't specify target table 't' for update in FROM clause
有一个表示地区的表,表结构与数据大概如下表. ID NAME PARENT_ID 1 中国 2 广东省 1 3 广州市 2 4 荔湾区 3 5 越秀区 3 6 番禺区 3 7 小谷围街道 6 现为了查 ...
随机推荐
- C++程序设计方法3:移动构造函数
移动拷贝构造函数 语法: ClassName(ClassName&&); 目的: 用来偷“临时变量”中的资源(比如内存) 临时变量被编译器设置为常量形式,使用拷贝构造函数无法将资源偷出 ...
- 关于EL表达式的学习总结
一.EL表达式简介 EL 全名为Expression Language.EL主要作用: 1.获取数据 EL表达式主要用于替换JSP页面中的脚本表达式,以从各种类型的web域 中检索java对象.获取数 ...
- Vue(十)生命周期
Vue生命周期 vue实例从创建到销毁的过程,称为生命周期,共有八个阶段 <script> window.onload=function(){ let vm = new Vue({ el: ...
- Annotation 的第一个工程
一.什么是 Annotation? java.lang.annotation,接口 Annotation.对于Annotation,是Java5的新特性,JDK5引入了Metadata(元数据)很容易 ...
- Nginx反向代理400错误
错误:使用Nginx的反向代理访问tomcat时400错误. upstream配置: upstream java_test{ server 127.0.0.1:8080; } 原因:nginx中ups ...
- jquery append 和appendTo
原文: https://www.cnblogs.com/stitchgogo/p/5721551.html ---------------------------------------------- ...
- Session variables lost after the call of Response.Redirect method
From: https://forums.asp.net/t/2096848.aspx?Session+variables+lost+after+the+call+of+Response+Redir ...
- 几种序列化协议(protobuf,xstream,jackjson,jdk,hessian)相关数据对比
测试结果 序列化数据对比 bytes字节数对比 具体的数字: protobuf jackson xstream Serializable hessian2 hessian2压缩 hessian1 ...
- Git diff结果显示分析
1.diff的三种格式: 正常格式(normal diff) 上下文格式(context diff) 合并格式(unified diff) 2.示例文件为了便于讲解,先新建两个示例文件.第一个文件叫做 ...
- 【PHP】解析PHP中的错误和异常处理
目录结构: contents structure [-] 错误级别 自定义处理器 设置异常日志 自定义异常类 在这篇文章中,笔者将会阐述PHP中的异常处理,希望能够对你有所帮助. 1.错误级别 PHP ...