关键词:mysql update,mysql delete

update中无法用基于被更新表的子查询,You can't specify target table 'test1' for update in FROM clause.

情况如下:

(1)第1行更新语句中,update表与子查询中表一样,所以报错

(2)第2行更新语句中,update表与子查询中表不一样,所以可以执行。

如何解决?

把子查询换成join即可。

例如:

总结:

  (1)在update与delete中,都不能再以子查询的方式调用其表本身(因为一致性的关系),否则会报错。

  (2)但可以以派生表的方式 join 使用

mysql中【update/Delete】update中无法用基于被更新表的子查询,You can't specify target table 'test1' for update in FROM clause.的更多相关文章

  1. mysql更新表数据时报错 You can't specify target table 'RES_CATALOG_CLASSIFY' for update in FROM clause

    You can't specify target table for update in FROM clause含义:不能在同一表中查询的数据作为同一表的更新数据. 将sql语句 UPDATE RES ...

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

  3. mysql中更新或者删除语句中子语句不能操作同一个表You can't specify target table 'test' for update in FROM clause

    问题描述:有个数据表test,有个字段value,如下 mysql> select * from test;+----+------------------------------------+ ...

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

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

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

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

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

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

  9. MySQL - 1093异常 - You can't specify target table 't' for update in FROM clause

    有一个表示地区的表,表结构与数据大概如下表. ID NAME PARENT_ID 1 中国 2 广东省 1 3 广州市 2 4 荔湾区 3 5 越秀区 3 6 番禺区 3 7 小谷围街道 6 现为了查 ...

随机推荐

  1. 树莓派上固定ip

    sudo nano /etc/dhcpcd.conf interface eth0 static ip_address=192.168.123.99/24 static routers=192.168 ...

  2. pull request的使用

    在git中,不少开发者对自己的提升非常看重,github中的开源项目就是一个非常好的学习资料. github中的开源项目并不是完全正确的,而成为项目贡献者是一件值得骄傲的事情. 所以如何才能对开源项目 ...

  3. gremlin语言语法--学习笔记

    学习gremlin语言的目的:测试图数据,支持gremlin语句,所以必须系统学习一下!!!! 一.基础查询 g.V() 查询所有的顶点 g.V(3) 查询顶点id为3的点.字符串id的要到引号V(& ...

  4. vue-element添加修改密码弹窗

    1.新建修改密码vue文件CgPwd.vue 代码如下: <template> <!-- 修改密码界面 --> <el-dialog :title="$t('c ...

  5. 使用Hybris Commerce User API读取用户信息时,电话字段没有返回

    在使用Hybris Commerce User API读取一个user信息时,我遇到一个问题,在API返回的结构里没有包含期望看到的Phone字段. 仔细观察Swagger里对response结构的说 ...

  6. IntelliJ IDEA VM options(转)

    Custom IntelliJ IDEA VM options # Custom IntelliJ IDEA VM options ##################JVM模式########### ...

  7. 分布式事务 GTS 的价值和原理浅析

    GTS 今年双 11 的成绩 今年 2684 亿的背后,有一个默默支撑,低调到几乎被遗忘的中间件云产品——GTS(全局事务服务,Global Transaction Service),稳稳地通过了自 ...

  8. [转]SQLServer : EXEC和sp_executesql的区别

    MSSQL为我们提供了两种动态执行SQL语句的命令,分别是EXEC和sp_executesql.通常,sp_executesql则更具有优势,它提供了输入输出接口,而EXEC没有.还有一个最大的好处就 ...

  9. 纯CSS手动滑动轮播图(隐藏滚动条)

    HTML: <div class="bigder"> <div class="big"> <dl> <dt>&l ...

  10. SpringCloud 教程 (二) 服务链路追踪(Spring Cloud Sleuth)

    一.简介 Add sleuth to the classpath of a Spring Boot application (see below for Maven and Gradle exampl ...