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 ...
随机推荐
- Node.js 学习笔记
时间:2016-07-07 提前安装好linux CentOs环境,以及相关工具(git,wget,vim……) 1.安装: 目前打算在CentOs上进行操作,网上有教程是旧的地址,这个是搬家后的新地 ...
- sp_helpdb
语法 sp_helpdb [ [ @dbname= ] 'name' ] 参数 [@dbname=] 'name' 是要为其提供信息的数据库名称.name 的数据类型为 sysname,无默认值.如果 ...
- with CTE AS
CTE/表变量/Temp http://www.cnblogs.com/ziyeyimeng/articles/2366855.html
- C#并行编程之数据并行
所谓的数据并行的条件是: 1.拥有大量的数据. 2.对数据的逻辑操作都是一致的. 3.数据之间没有顺序依赖. 运行并行编程可以充分的利用现在多核计算机的优势.记录代码如下: public class ...
- HDU 5055 Bob and math problem(简单贪心)
http://acm.hdu.edu.cn/showproblem.php?pid=5055 题目大意: 给你N位数,每位数是0~9之间.你把这N位数构成一个整数. 要求: 1.必须是奇数 2.整数的 ...
- hduoj 1285 确定比赛名次
http://acm.hdu.edu.cn/showproblem.php?pid=1285 确定比赛名次 Time Limit: 2000/1000 MS (Java/Others) Memory ...
- newtonsoft.json 序列化,反序列化
public class Book { public string BookID { get; set; } public DateTime PublishDate { get; set; } pub ...
- GPT WIN 换硬盘 硬盘克隆或复制 无法确定的问题,硬盘大小不一致换系统。
当你购买了一个新硬盘,希望换掉旧硬盘的时候.发现 GPT + EFI 要求硬盘上的前两个分区必须和旧的一样,否则就无法启动. 这就是你用 分区大师(PartAssist)硬盘克隆完了,也无法启动的原因 ...
- Ring buffers and queues
Ring buffers and queues The data structure is extremely simple: a bounded FIFO. One step up from pla ...
- 使用tmpfs作为缓存加速缓存的文件目录
使用tmpfs作为缓存加速缓存的文件目录 [root@web02 ~]# mount -t tmpfs tmpfs /dev/shm -o size=256m[root@web02 ~]# mount ...