You can't specify target table 'xxx' for update in FROM clause
1、执行sql语句报上面的错误:
DELETE
FROM
db_student
WHERE
RowGuid IN ( SELECT RowGuid FROM db_student WHERE age = GROUP BY RowGuid HAVING count( * ) > )
AND ID NOT IN ( SELECT MAX( ID ) AS id FROM db_student WHERE age = GROUP BY RowGuid HAVING count( * ) > )
报错如下所示
You can't specify target table 'xxx' for update in FROM clause。
原因:因为在MYSQL里,不能先select一个表的记录,在按此条件进行更新和删除同一个表的记录。
详细参考:https://blog.csdn.net/h996666/article/details/81699255
SELECT *
FROM
db_student
WHERE
RowGuid IN (
SELECT
aa.RowGuid
FROM
( SELECT RowGuid FROM db_student WHERE age = GROUP BY RowGuid HAVING count( * ) > ) aa
)
AND ID NOT IN (
SELECT
t.id
FROM
( SELECT MAX( ID ) as id FROM db_student WHERE age = GROUP BY RowGuid HAVING count( * ) > ) t
) DELETE
FROM
db_student
WHERE
RowGuid IN (
SELECT
aa.RowGuid
FROM
( SELECT RowGuid FROM db_student WHERE age = GROUP BY RowGuid HAVING count( * ) > ) aa
)
AND ID NOT IN (
SELECT
t.id
FROM
( SELECT MAX( ID ) as id FROM db_student WHERE age = GROUP BY RowGuid HAVING count( * ) > ) t
)
待续......
You can't specify target table 'xxx' for update in FROM clause的更多相关文章
- 错误:You can't specify target table 'xxx' for update in FROM clause的解决
问题: 今天在MySQL数据库删除重复数据的时候遇到了一个问题.如下脚本: DELETE FROM tempA WHERE tid IN ( SELECT MAX(tid) AS tid FROM t ...
- 关于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 You can't specify target table 'xxx' for update in FROM clause
含义:您不能在子句中为更新指定目标表'xxx'. 错误描述:删除语句中直接含select,如下: DELETE FROM meriadianannotation WHERE SeriesID IN ( ...
- 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 ...
- django.db.utils.OperationalError: (1093, "You can't specify target table 'xxx' for update in FROM clause")
这个错误的意思是,不能在update某张表的where条件中,再次select这张表的某些值作为筛选条件,比如: update message set content = "hello&qu ...
- You can't specify target table 'a' for update in FROM clause
项目中有一个功能变动上线,其中有一张表ttt的字段cc,历史数据需要处理,把字段cc中为'xxx'的值替换为'yyy'. 表A结构如下: CREATE TABLE `ttt` ( `id` bigin ...
- mysql中更新或者删除语句中子语句不能操作同一个表You can't specify target table 'test' for update in FROM clause
问题描述:有个数据表test,有个字段value,如下 mysql> select * from test;+----+------------------------------------+ ...
- mysql的一个特殊问题 you can't specify target table 'cpn_regist' for update in FROM clause
今天在操作数据库的时候遇到了一个问题,sql语句如下: UPDATE cpn_yogurt_registration SET dep1Name = '1' WHERE `key` in (SELEC ...
- 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 ...
随机推荐
- centos安装python的虚拟环境和虚拟管理环境
一.大部分介绍的方式是使用pip安装:1.pip install virtualenv 2.pip install virtualenvwrapper 但是我安装完,并没有相应的命令:virt ...
- 王立平--Gallery:实现图片的左右滑动
<span style="font-size:18px;color:#330033;">package com.main; import android.app.Act ...
- jdk与jre安装之后的名字
jdk与jre安装之后的名字 jdk与jre的区别:https://blog.csdn.net/qq_33642117/article/details/52143824 jdk安装之后的名字: Jav ...
- start_kernel——mm_init_owner
全部任务都具有自己的内存,启动阶段中的当前任务必须具备属于自己的内存. mm_init_owner()函数传递init_mm和init_task參数 mm/init-mm.c struct mm_st ...
- oracle 静默安装
下载oracle的安装包: 下载地址: 注意下载oracle是须要注冊oracle的 http://download.oracle.com/otn/nt/oracle11g 下载两个包: linux. ...
- Unity ----- 对象池GameObjectPool
孙广东 2014.6.28 非常早之前看到的外国文章,认为不错,分享一下. 对象池在AssetStore中也是有非常多插件的,可是有些重了.自己写一个轻量的岂不是非常好. 当你须要创建大量某种类型对象 ...
- 字符串类型ip与数值型ip地址相互转换
/** * 返回Integer类型的ip地址 * @return */ private static Integer ipToInt(){ String ip="192.168.1.201& ...
- CPU Stepping
http://baike.baidu.com/view/16839.htm?fr=ala0_1_1 步进 编辑 步进(Stepping)是CPU的一个重要参数,也叫分级鉴别产品数据转换规范,“步进 ...
- 用JAVA编写浏览器内核之实现javascript的document对象与内置方法
原创文章.转载请注明. 阅读本文之前,您须要对浏览器怎样载入javascript有一定了解. 当然,对java与javascript本身也须要了解. 本文首先介绍浏览器载入并执行javascript的 ...
- 使用ViewPager多页面滑动切换以及动画效果
https://github.com/eltld/Viewpager