问题描述:有个数据表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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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这个表( ...

  4. 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 ...

  5. 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 ...

  6. 关于mysql 5.7版本“报[Err] 1093 - You can't specify target table 'XXX' for update in FROM clause”错误的bug

    不同于oracle和sqlserver,mysql并不支持在更新某个表的数据时又查询了它,而查询的数据又做了更新的条件,因此我们需要使用如下的语句绕过: , notice_code ) a) ; 本地 ...

  7. 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 ...

  8. 【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 原因 待更新/删除的数据集与查询的 ...

  9. Mysql -- You can't specify target table 'address' for update in FROM clause

    做地址管理时,需要先根据要设为默认的地址的用户将用户的其他地址都设置为非默认 需要select出用户id然后update 原语句 update address set isdeafult = 0 wh ...

随机推荐

  1. mysql 工具箱

    创建测试数据 存储过程: delimiter // create procedure sp_generate_data() begin ; do set @created_time := date_a ...

  2. WebForm Repeater使用

    Repeater: HeaderTemplate: 在加载开始执行一遍 ItemTemplate : 有多少条数据,执行多少遍 FooterTemplate :在加载最后执行一遍 Alternatin ...

  3. 几个js函数

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  4. 使用filter获取http请求的出参以及入参

    首先 我们的目的是做一个拦截器 能够对http请求做profiler,能够记录本次的调用情况,这里说下如何从http请求中获取到出参的问题. 方案一:参照http://blog.csdn.net/wu ...

  5. 我认识的log4j开源日志

    Log4j 在java中如何配置log4j!! 步骤: ①引入jar包,推荐新建一个lib文件夹,用来装所有的jar包(还要进行下图内的操作) 之后项目中就会多出一个引入外部Library的项目 ②创 ...

  6. [转]在windows环境中使用varnish

    varnish 的windows 版本下载地址: http://sourceforge.net/projects/cygvarnish/files/windows-zip-bundle/ 启动:var ...

  7. PHP文件操作:遍历文件目录

    <?php /*遍历目录,列出目录中的文件 * array scandir(string $directory [,int $sorting_order]) * $directory为待遍历目录 ...

  8. pm2.5计算和单位换算

    1.pm2.5和pm10的计算  PM10a=PM10+PM25a PM25a=PM25+BC+OC+SOA1+SOA2+SOA3+SOA4+SOA5+SOA6+ANA+ASO4+ANO3+ACL+A ...

  9. ftp协议详解

    客户端与服务器之间,需要多条连接才能完成应用的协议,属于复杂协议.如FTP,PPTP,H.323和SIP均属于复杂协议. 这里主要介绍ftp协议的工作原理.首先,ftp通信协议有两种工作模式,被动模式 ...

  10. C# 调用存储过程操作 OUTPUT参数和Return返回值

    本文转载:http://www.cnblogs.com/libingql/archive/2010/05/02/1726104.html 存储过程是存放在数据库服务器上的预先编译好的sql语句.使用存 ...