mysql用查询结果当删除的判断条件进行删除报错1093 You can't specify target table解决方法

#分开两个sql执行正常的语句,只保留最新1000条数据,删掉1000条以前的旧数据
select number from historydata order by number desc limit 1001,1;
delete from historydata where number < 201911270538;
#直接合并后报错:错误代码: 1093 You can't specify target table 'historydata' for update in FROM clause
delete from historydata where number < (select number from historydata order by number desc limit 1001,1);

#意思是:在同一语句中,不能先select出同一表中的某些值,再update这个表
#将select出的结果再通过中间表select一遍,可以规避这个错误
delete from historydata where number < (
select w.number from (
select historydata.number from historydata order by historydata.number desc limit 1001,1
)w
);

注意:select w.number 这个w前面不能有多个空格或者tab键的隐藏字符,否则会报找不到 w.number的错误。

mysql用查询结果当删除的判断条件进行删除报错1093 You can't specify target table解决方法的更多相关文章

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

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

  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 1093 - You can't specify target table 'sc' for update in FROM clause

    错误代码如下: #(8) 把"邓维杰"同学的成绩全部删除. SELECT * FROM sc WHERE EXISTS(SELECT * FROM student WHERE st ...

  4. mysql 1093 - You can't specify target table 'xx表' for update in FROM clause

    为了修复节点表某批次数据的用户数据,做出了以下尝试: , name , , )); 执行:[Err] 1093 - You can't specify target table 'zs_work_ap ...

  5. MYSQL如何在创建表时添加判断条件

    大家好,我是小皓. 一.背景 今天在博主练习MYS创建表操作时遇到一个语法报错,就想着来和大家分享一下MYSQL如何在创建表时添加判断条件: ERROR 1064 (42000): You have ...

  6. mysql中大数据表alter增加字段报错:"1034 Incorrect key file for table 'table_name'; try to repair it"

    mysql中大数据表alter增加字段报错:"1034 Incorrect key file for table 'table_name'; try to repair it" 现 ...

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

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

  9. 密码正确 mysql无法登陆 red7.3 上安装mysql5.6后登录报错ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using passswd :yes)

    集群需要mysql存储元数据,就在前几天还运行好好的,突然就进不去了......还是太菜,遇到的bug少. 引起这种故障的原因有很多......第一个坑比较多,大部分用户也就用第一个就可以解决问题,我 ...

随机推荐

  1. 01 python的安装

    下载3.7.0版本 然后点击 close  关闭 1-==>搜索输入“cmd”输入 “python -V”并回车. 出现版本说明安装成功.2==>>>> 是提示符3=== ...

  2. 【bzoj2648】SJY摆棋子(kdtree)

    传送门 题意: 二维平面上有若干个点. 现在要维护一种数据结构,支持插入一个点以及询问其余点到某个点的最小曼哈顿距离. 思路: 这是个\(kdtree\)模板题. \(kdtree\)是一种可以高效处 ...

  3. luoguP2163 [SHOI2007]园丁的烦恼

    安利系列博文 https://www.cnblogs.com/tyner/p/11565348.html https://www.cnblogs.com/tyner/p/11605073.html 题 ...

  4. Python高级特性之:List Comprehensions、Generator、Dictionary and set ...

    今天帅气的易哥和大家分享的是Pyton的高级特性,希望大家能和我一起学习这门语言的魅力. Python高级特性之:List Comprehensions.Generator.Dictionary an ...

  5. 《深度学习》圣经"花书"经验法则中文版!

    作者:Jeff Macaluso https://jeffmacaluso.github.io/post/DeepLearningRulesOfThumb/ 转自CVer,仅用作个人学习 当我在研究生 ...

  6. python将xml文件数据增强(labelimg)

    在处理faster-rcnn和yolo时笔者使用labelimg标注图片 但是我们只截取了大概800张左右的图,这个量级在训练时肯定是不够的,所以我们需要使用数据增强(无非是旋转加噪调量度)来增加我们 ...

  7. 鲜贝7.3--Xshell安装

    安装包百度云下载地址:https://blog.csdn.net/yueruitao/article/details/85263968 具体方法请参考: https://blog.csdn.net/q ...

  8. AtCoder Beginner Contest 147

    A - Blackjack #include <bits/stdc++.h> int main() { int a, b, c; scanf("%d%d%d", &am ...

  9. 43 树莓派安装pytorch

    狗狗 https://www.pytorchtutorial.com/pytorch-c-api-4-cat-dog-classifier-2/ 鲜花分类器 https://www.pytorchtu ...

  10. Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) E. Rock Is Push dp

    E. Rock Is Push You are at the top left cell (1,1) of an n×m labyrinth. Your goal is to get to the b ...