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. 0基础入门学习Python(第3章)

    第三章 成为高手前必须知道的一些基础知识 3.1 变量 一个值的名字,存储在内存中,我把把这块内存称为变量,大多数语言,把这个过程称之为,给变量赋值,把值存储在变量中. Python这里的做法稍有不同 ...

  2. SQLi-LABS Page-4 (Challenges) Less-54-Less-65

    Less-54 union - 1 http://10.10.202.112/sqli/Less-54?id=-1' union select 1,2,group_concat(table_name) ...

  3. 升鲜宝V2.0_生鲜配送行业,对生鲜配送行业的思考及对系统流程开发的反思_升鲜宝生鲜配送系统_15382353715_余东升

    升鲜宝V2.0_生鲜配送行业,对生鲜配送行业的思考及对系统流程开发的反思_升鲜宝生鲜配送系统_15382353715_余东升 -----生鲜配送行业现状及存在问题----- 1.  从业者整体素质偏低 ...

  4. 使用Wireshark进行DNS协议解析

    - 域名及解析过程 域名由一系列 - DNS协议报文格式 一次DNS过程包含一对请求报文和响应报文.请求和响应报文有统一的报文格式如下图: - DNS报文例子 一次DNS请求的过程: 包括请求和响应, ...

  5. Linux 下Postgresql 命令:

    关闭:service postgresql stop 启动:service postgresql start 启动数据库:pg_ctl start -D /data/postgres 重启数据库: p ...

  6. C学习笔记(8)--- 文件读写

    1.C 文件读写: 一个文件,无论它是文本文件还是二进制文件,都是代表了一系列的字节.C 语言不仅提供了访问顶层的函数,也提供了底层(OS)调用来处理存储设备上的文件. a.打开文件: FILE *f ...

  7. RC4 对称加密

    public class RC4 { byte[] s = new byte[256]; byte[] key; byte keylen;// 4 ~ 16 int pi = 0; int pj = ...

  8. java中的字符串一

    public class TestString2 { public static void main(String[] args) { //判断两字符串是否相等 String s1 = "H ...

  9. vue中keepAlive的使用

    在开发中经常有从列表跳到详情页,然后返回详情页的时候需要缓存列表页的状态(比如滚动位置信息),这个时候就需要保存状态,要缓存状态:vue里提供了keep-alive组件用来缓存状态.可以用以下几种方案 ...

  10. npm ERR! Cannot read property 'resolve' of undefined

    一 .有可能是版本过低,或者软件损坏,重新安装一下试试 地址