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. 从《华为的冬天》到AI的冬天 | 甲子光年

    知难不难,惶者生存. 作者 | DougLong 编辑 | 火柴Q.甲小姐 *本文为甲子光年专栏作家DougLong独家稿件.作者为AI从业者.Gary Marcus<Rebooting AI& ...

  2. .net连接Oracle

    通过网上了解到.net连接Oracle主要有3种方法.(1)System.Data.OracleClient微软的System.Data.OracleClient可以直接引用,但是VS会提示“Syst ...

  3. 使用 gitlab 进行代码管理

    这里使用 gitlab 做服务器, 客户端主要使用 git extensions. ============================= gitlab 项目成员类型: ============= ...

  4. IDEA设置默认WorkingDirectory

  5. rabbitmq pika(python)订阅发布多客户端消费场景简单使用

    发布端: import pika import time credentials = pika.credentials.PlainCredentials('root', 'root',erase_on ...

  6. 学习:SpringCloud(一)

    微服务: 微服务是一种架构模式或者一种架构风格,提倡将单一应用程序划分成一组小的服务==独立部署==,服务之间相互配合.相互协调,每个服务运行于自己的==进程==中. 服务与服务间采用轻量级通讯,如H ...

  7. linux 创建虚拟块设备,制作文件系统并挂载,用于测试lustre

    1.制作块文件 3 个 [root@localhost yaoxu]# [root@localhost yaoxu]# [root@localhost yaoxu]# 2.创建回环设备 [root@l ...

  8. 微软发布Visual Studio Online公共预览版和ML.NET 1.4

    在今天的Ignite 2019上,Microsoft启动了 Visual Studio Online 公共预览版.Visual Studio Online将Visual Studio,云托管的开发人员 ...

  9. 13. 抽象类 & 接口

    一.抽象类 // 抽象类Shape public abstract class Shape { // 1. 成员变量 private String color; // 2. 初始化块 { System ...

  10. LeetCode 回文串问题

    5. Longest Palindromic Substring 647. Palindromic Substrings 解法一:从中心一点向两边扩展,需要考虑中心为一点,中心为两点. 解法二:马拉车 ...