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 ...
随机推荐
- 使用 apache2 + `mod_proxy_uwsgi` + uwsgi + upstart 部署
使用 apache2 + mod_proxy_uwsgi + uwsgi + upstart 部署 网上运行 python wsgi 的应用时,大部分的资料都是使用 nginx .uwsgi ,很少资 ...
- 合并分区(merge range)对事务日志的影响
分区维护作业执行失败,错误信息如下:数据库 'XXX' 的事务日志已满.若要查明无法重用日志中的空间的原因,请参阅 sys.databases 中的 log_reuse_wait_desc 列. [S ...
- windows---------------windows如何查看哪个应用占用了哪个端口的方法
假如我们需要确定谁占用了我们的80端口在windows命令行窗口下执行:netstat -aon|findstr "80"TCP 127.0.0.1:80 0.0.0.0:0 LI ...
- vbs让电脑发音说话
Dim vbs1 'set vbs1 = WScript.CreateObject("WScript.Shell") set vbs1 = WScript.CreateObject ...
- R语言学习-基础篇
从五月10日开始自学R in action,将我的学习所得逐渐发布在博客上. chapter1.新手上路 工作空间:存储着所有用户定义的对象(向量,矩阵,函数,数据框,列表): 当前的工目录保存是R用 ...
- Asp.net MVC5 框架揭秘 S412 实例解析 – 绝妙的扩展 模式的胜利
Asp.net MVC5 框架是个 开源的,处处可扩展的框架. 蒋先生 在他的这本书里 对如何理解框架,如何扩展框架, 给出了大量的说明和实例. 先上效果图 大部分做传统BS 的同学看到这个页面,脑海 ...
- java 中构造函数 的理解
构造方法就是与类同名的那个方法,它的作用是可以用来初始化 class Person{ public Person(String n,int a) {//构造方法 name = n; age = a; ...
- 非常强大的table根据表头排序,点击表头名称,对其内容排序
js代码: /** * 通过表头对表列进行排序 * * @param sTableID * 要处理的表ID<table id=''> * @param iCol * 字段列id eg: 0 ...
- Oracle数据库学习笔记
创建表的同时插入数据:create table zhang3 as select * from zhang1;create table zhang3(id,name) as select * from ...
- dr.wondr博士随笔之三星某智能机的SGHXXXX 的取证恢复一例
大家好!欢迎今天再次来到我dr.wonde的博客, 今天我给大家带来一款三星镜面古董机SGH-E848的取证展示! 三星SGH-E848是一款非常漂亮的镜面手机,2008年出厂.. 上面黄色是97号数 ...