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 ...
随机推荐
- express---express-session axios
express---express-session axios 使用axios访问后台获取session中的属性值为undefined 在main.js中导入axios import axios fr ...
- 23. 客户默认选项(Default Customer Options)
Editing Email Templates Email Sender Contact Us
- Map与object的区别
Map 对象保存键值对.任何值(对象或者原始值) 都可以作为一个键或一个值. 语法 new Map([iterable]) 参数 iterable Iterable 可以是一个数组或者其他 itera ...
- BUPT复试专题—中序遍历序列(2013)
题目描述 给出一个序列,判断该序列是不是某二叉搜索树的中序遍历序列,如果是输出"Yes",否则输出"No".一颗带权二叉树是一颗二叉搜索树(二叉排序树),当且仅 ...
- [Adobe Analytics] Segments types
There are three types of Segmentation Hit-based Visit-based Visitor-based There are four segment con ...
- JDBC MYSQL 学习笔记(一) JDBC 基本使用
1.JDBC简单介绍 SUN公司为了简化.统一对数据库的操作,定义了一套Java操作数据库的规范.称之为JDBC. JDBC全称为:Java Data Base Connectivity(java数据 ...
- 增强版的RecycleViewAdapter,能够直接使用
在Android的项目中.须要大量的列表组件来显示数据.在之前的项目中一直使用的是ListView 组件,可是在最新的V7包中出现了能后替代ListView的组件RecycleView. 所以在新的项 ...
- [ACM] POJ 3253 Fence Repair (Huffman树思想,优先队列)
Fence Repair Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 25274 Accepted: 8131 Des ...
- 解决最新版的ADT没有NDK选项的问题
最新版的ADT不显示NDK,解决方法有两种,第一种方法在线重装一下 这种方法有一个问题就是,google的东西我们经常不能访问,解决方法可以参考http://blog.csdn.net/shi_wei ...
- UnsatisfiedLinkError: No implementation found for , AndroidStudio使用*.so
今天工作的时候.发现了一个jni的问题,java.lang.UnsatisfiedLinkError: No implementation found for...... 问题1:后来查了资料后发现. ...