mysql中更新或者删除语句中子语句不能操作同一个表You can't specify target table 'test' for update in FROM clause
问题描述:有个数据表test,有个字段value,如下
mysql> select * from test;
+----+------------------------------------+
| id | value |
+----+------------------------------------+
| 3 | 3aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
| 4 | 4aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
| 5 | 5aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
| 6 | 6aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
| 7 | 7aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
如果执行如下sql语句会报错
delete from test where id=(select min(id) from test);
报的错误是You can't specify target table 'test' for update in FROM clause。
原因是不能在操作一张表的同时更新或者删除这张表的内容。
解决方法如下:(3个步骤)
create table tmp as select min(id) as col1 from test;
delete from test where id =(select col1 from tmp);
drop table tmp
这时又遇到一个问题,如何在php中一次执行多个sql语句(当然也可以分3次执行),此问题待查
mysql中更新或者删除语句中子语句不能操作同一个表You can't specify target table 'test' 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中【update/Delete】update中无法用基于被更新表的子查询,You can't specify target table 'test1' for update in FROM clause.
关键词:mysql update,mysql delete update中无法用基于被更新表的子查询,You can't specify target table 'test1' for update ...
- mysql You can't specify target table 'sys_org_relation' for update in FROM clause 删除表条件不能直接包含该表
mysql中You can't specify target table for update in FROM clause错误的意思是说,不能先select出同一表中的某些值,再update这个表( ...
- mysql 更新sql报错:You can't specify target table 'wms_cabinet_form' for update in FROM clause
数据库里面有两个字段的位置不对,要把他们对调换下.因为没有数据库写的权限,需要用sql语句来实现.原来以为简单的 update table a set a.字段a=(select b字段 from t ...
- 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 ...
- 关于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 'sc' for update in FROM clause
错误代码如下: #(8) 把"邓维杰"同学的成绩全部删除. SELECT * FROM sc WHERE EXISTS(SELECT * FROM student WHERE st ...
- 【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 -- You can't specify target table 'address' for update in FROM clause
做地址管理时,需要先根据要设为默认的地址的用户将用户的其他地址都设置为非默认 需要select出用户id然后update 原语句 update address set isdeafult = 0 wh ...
随机推荐
- Autorelease自动释放池的使用
Autorelease自动释放池的使用 使用ARC开发,只是在编译时,编译器会根据代码结构自动添加了retain.release和autorelease. MRC内存管理原则:谁申请,谁释放 遇到al ...
- SpringMVC操作指南-登录功能与请求过滤
[1] Source http://code.taobao.org/p/LearningJavaEE/src/LearningSpringMVC005%20-%20Login%20and%20Filt ...
- postgresql查询的处理过程
本文简单描述了Postgresql服务器接收到查询后到返回给客户端结果之间一般操作顺序,总的流程图如下: 第一步: 客户端程序可以是任何符合 PostgreSQL 协议规范的程序,如 JDBC 驱动. ...
- Sass与Web组件化相关的功能
Sass https://en.wikipedia.org/wiki/Sass_(stylesheet_language) Sass (Syntactically Awesome Stylesheet ...
- Android四大组件之Activity
实验内容 了解Activity的四个状态 Activity的生命周期 启动另外一个Activity 实验要求 编码实现观察Activity的生命周期函数执行过程 编码实现启动另外一个Activity ...
- 【转】Win8下安装SQL Server 2005无法启动服务
安装了Windows8,但是发现不支持Sql Server 2005的安装.网上找了很多办法,基本上都有缺陷.现在终于找到一种完全正常没有缺陷的办法了,和大家分享一下. 1.正常安装任一版本的SQL ...
- 第九章伪代码编程过程 The PseudoCode Programming Process
目录: 1.创建类和子程序的步骤概述 2.伪代码 3.通过伪代码编程过程创建子程序 4.伪代码编程过程的替代方案 一.创建类和子程序的步骤概述 (1)创建一个类的步骤 1.创建类的总体设计 2.创建类 ...
- hadoop的学习
http://www.aboutyun.com/thread-6179-1-1.html
- 浅谈JSON.stringify 函数与toJosn函数和Json.parse函数
JSON.stringify 函数 (JavaScript) 语法:JSON.stringify(value [, replacer] [, space]) 将 JavaScript 值转换为 Jav ...
- 基于ssh框架的在线考试系统开发的质量属性
我做的系统是基于ssh框架的在线考试系统.在线考试系统有以下几点特性:(1)系统响应时间需要非常快,可以迅速的出题,答题.(2)系统的负载量也需要非常大,可以支持多人在线考试(3)还有系统的安全性也需 ...