问题描述:有个数据表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. ORA-03113: end-of-file on communication channel

    导致的原因,可能是异常断电导致文件状态不一致. SQL> startupORACLE instance started. Total System Global Area 1653518336 ...

  2. eclipse下导入jdk源码

    一直想好好看看jdk的源码,虽然可以直接解压jdk下的src看,但是终究不方便!后来发现可以导入到eclipse中,就在网上找了一些方法,下面就和大家分共享: step1:打开eclipse选择Win ...

  3. VS工程添加资源文件

    1. 添加资源文件: 2. 资源文件内写相应代码: <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006 ...

  4. [CC]LOD技术

    ccGLWindow::paintGL() | ccGLWindow::fullRenderingPass(...) | ccGLWindow::drawBackground(context, ren ...

  5. js判断手指滑动方向(移动端)

    var startx, starty; //获得角度 function getAngle(angx, angy) { return Math.atan2(angy, angx) * 180 / Mat ...

  6. 只需三步--轻松反编译Android Apk文件

    安卓程序是通过java语言进行编写的,可以很容易进行反编译.很多apk文件被反编译后再二次打包,就成了自己的产品,很是流氓.下面我们来看看如何进行apk的反编译,以及常用的防反编译手段. 一.反编译A ...

  7. ubuntu 15.04 安装配置 JDK1.8

    1.到oracle的官网下载 http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 选 ...

  8. HTML5音频视频-视频播放

  9. 真正shopex分销王2代DRP系统源码正版安装版本终身商业授权

    真正ShopEx分销王系统2代正版授权.该商业程序已经完整授权,已测试100%完整能用.很多朋友来问是否免费版的源码?错,这是和官方一样的平台版本,100%无限制功能使用,跟官方付费使用的授权版一样. ...

  10. github 删除仓库 repository

    1.点开想要删除的仓库 2点击setting 3.拉到最下面 4.点击 Delete this repository 5.输入想删除仓库的名字 点击