zoukankan      html  css  js  c++  java
  • Mysql大数据表删除重复数据

    对没有索引的字段进行查询重复时如果使用select name from table where name in(select name from table group by name having count(name)>1)这类查询,效率非常低,是不可取的,下面给出替代步骤:

    1.根据重复记录创建临时表

    create table   temptable as (

       select title from video

        GROUP BY title HAVING count(title) >1

    );

    2.查询重复数据

    select a.* from temptable t,video a where a.title=t.title;

    下面给出实际中我使用的删除重复数据的脚本,供参考:

    create table   temptable as (
    
       select MAX(id) as id  from video
    
        GROUP BY title HAVING count(title) >1
    
    );
    delete  from video where id in (select id from temptable) order by id ;
    drop table temptable;
  • 相关阅读:
    UNIX常用shell
    exit函数
    linux消息队列
    互斥量
    RCS版本控制
    linux samba
    UML建模
    linux syslog
    python基础-列表List及内置方法
    仿美团详情页与购物车源码-详情页
  • 原文地址:https://www.cnblogs.com/zhishan/p/3099523.html
Copyright © 2011-2022 走看看