mysql中You can't specify target table for update in FROM clause错误的意思是说,不能先select出同一表中的某些值,再update这个表(在同一语句中)。

例:DELETE from sys_org_relation where pOrgid in (

select porgId from sys_org_relation   r  where  r.corgid='客户id' and relationType=1112

)  and  and relationType=1213;

该语句中要操作的sys_org_relation 表条件也是来自sys_org_relation 表查询的结果,此时会抛出 You can't specify target table 'sys_org_relation' for update in FROM clause异常

解决办法:

需要一个中间转换的表,也就是说将select出的结果再通过中间表select一遍,这样就规避了错误。注意,这个问题只出现于mysql,mssql和oracle不会出现此问题。

应改为以下:

DELETE from sys_org_relation where pOrgid in (

  select a.corgidfrom (

    select corgidfrom sys_org_relation   r  where  r.porgid='客户id' and relationType=1112

  )  a

)  and  and relationType=1213;

mysql You can't specify target table 'sys_org_relation' for update in FROM clause 删除表条件不能直接包含该表的更多相关文章

  1. mysql You can't specify target table 'sys_right_menu' for update in FROM clause (不能从Objor子句中指定目标表“SysRyType菜单)

    错误语句: DELETE from sys_right_menu where right_id  in (SELECT m.right_id from sys_right_menu  mLEFT JO ...

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

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

  3. mysql You can't specify target table 'xxx' for update in FROM clause的解决

    DELETE from sp_goodscontent where goodsId in (SELECT t.goodsId from ( SELECT goodsId FROM sp_goodsco ...

  4. mysql You can't specify target table 'xxx' for update in FROM clause

    含义:您不能在子句中为更新指定目标表'xxx'. 错误描述:删除语句中直接含select,如下: DELETE FROM meriadianannotation WHERE SeriesID IN ( ...

  5. Mysql You can't specify target table 'newsalrecord' for update in FROM clause

    这个问题是不能先select出同一表中的某些值,再update这个表(在同一语句中),即不能依据某字段值做判断再来更新某字段的值.解决办法就是建立个临时的表.

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

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

  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中执行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 ...

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

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

随机推荐

  1. Mysql根据数据库的时间字段到点更新另外的状态。

    转载:https://blog.csdn.net/xingfuzhijianxia/article/details/53727820 需求如下: 添加一条提醒,被提醒人在提醒时间未到达的时候收不到此提 ...

  2. ios开发-常见的项目文件介绍

    一.项目文件结构示意图 二.文件介绍 1.products文件夹:主要用于mac电脑开发的可执行文件,ios开发用不到这个文件 2.frameworks文件夹主要用来放依赖的框架 3.test文件夹是 ...

  3. [书目20150303]软件工程的本质:运用SEMAT内核

    译者序Robert Martin作序Bertrand Meyer作序Richard Soley作序前言致谢第一部分   内核思想解释第1章   简要介绍如何使用内核1.1   为什么开发优秀软件具有很 ...

  4. SSM学习

    一.https://www.cnblogs.com/zyw-205520/p/4771253.html 二.https://blog.csdn.net/dwhdome/article/details/ ...

  5. turn协议的工作原理

    Allocate请求 客户端通过发送Allocate请求给STUN服务器,从而让STUN服务器为A用户开启一个relay端口.     a) 客户端A向STUN Port发送Allocate请求(图中 ...

  6. 【转】qqface使用实例

    原网址:http://www.xwcms.net/js/bddm/51565.html <div id="show"></div>   <div cl ...

  7. Xamarin.Forms跨平台开发入门-第二部分:深入解析

    英文原文: https://developer.xamarin.com/guides/xamarin-forms/getting-started/hello-xamarin-forms/deepdiv ...

  8. 修改xampp的mysql默认密码和端口

    修改MySQL默认密码 MySQL 的“root”用户默认状态是没有密码的,所以在 PHP 中您可以使用 mysql_connect("localhost","root& ...

  9. vuex的应用和解决的实际问题

    这是vuex的语法结构内容 简单的理解vuex: new Vue({ // state data () { return { count: 0 } }, // view template: ` < ...

  10. Java之抽象和封装

    ① 如何从现实世界中抽象出类?    根据软件开发需求: 发现类-->发现类的属性-->发现类的方法    ②   构造方法的作用和特点是什么?    作用:在创建对象时执行一些初始化操作 ...