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. Android SearchView不显示搜索icon

    版权声明:本文为xing_star原创文章,转载请注明出处! 本文同步自http://javaexception.com/archives/80 背景: 之前碰到了一个页面展示问题,SearchVie ...

  2. LeetCode——Delete Duplicate Emails(巧用mysql临时表)

    Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique ...

  3. Lnmp架构部署动态网站环境.2019-7-3-1.3

    Php安装 一.安装准备 1.Php依赖包 [root@Lnmp tools]# yum install -y zlib libxml libjpeg freetype libpng gd curl ...

  4. 【BZOJ2655】calc(拉格朗日插值)

    bzoj 题意: 给出\(n\),现在要生成这\(n\)个数,每个数有一个值域\([1,A]\).同时要求这\(n\)个数两两不相同. 问一共有多少种方案. 思路: 因为\(A\)很大,同时随着值域的 ...

  5. 泛型T

    作用: 使用泛型类型可以最大限度地重用代码.保护类型的安全以及提高性能. 泛型最常见的用途是创建集合类 1.性能:如List<object> 与 List<T> 将一个 int ...

  6. Windows环境下搭建Redis集群(Redis-x64-3.2.100)

    一 .前期准备Redis.Ruby语言运行环境.Redis的Ruby驱动redis-xxxx.gem.创建Redis集群的工具redis-trib.rb 二.安装配置redisredis下载地址 ht ...

  7. 第七周第二次Scrum会议

    工作: 根据上个周对前端的布置学习,布置大家开发了相应的界面.(界面开发成果写在测试报告) 地点: 二餐二 会议照片: 忘记拍了... 核心问题: 如何编写统一风格的前端界面. 解决: 将相应资源打包 ...

  8. luogu4570 元素

    题目链接 problem 有\(n\)个二元组, \((x,y)\),要选出一些二元组,使得他们的\(x\)的任何一个子集的异或和不为\(0\)并且\(y\)的和最大. solution 考虑是\(x ...

  9. HMM AND CRF

    Structured Learning 4: Sequence Labeling:https://www.youtube.com/watch?v=o9FPSqobMys HMM crf 李宏毅老师讲的 ...

  10. Linux 网络通信 API详解【转载】

    TCP/IP分层模型 OSI协议参考模型,它是基于国际标准化组织(ISO)的建议发展起来的, 它分为7个层次:应用层.表示层.会话层.传输层.网络层.数据链路层及物理层. 这个7层的协议模型虽然规定得 ...