zoukankan      html  css  js  c++  java
  • SQL去重复数据

    1、查找表中重复数据,重复数据以单个字段(title)为标识

    select id,title from t_article 
    where title in (
      select title from (
        select title as title from t_article 
        group by title having count(title) > 1
      ) as title
    )
    order by title

    2、删除表中多余的重复数据,重复数据以单个字段(title)为标识,只留有id最小的数据

    delete from t_article 
    where title in (
      select title from (
        select title as title from t_article 
        group by title having count(title) > 1
      ) as title
    )
    and id not in (
      select id from (
        select min(id) as id from t_article t group by title having count(title) > 1
      ) as id
    );

    3、查找表中重复数据,重复数据以(title,source)多个字段为标识

    select id,title,source,upload_time from t_article 
    where (title,source) in (
      select title,source from t_article 
      group by title,source having count(*) > 1
    )
    order by title

    4、删除表中多余的重复数据,重复数据以(title,source)多个字段为标识,只留有id最小的数据

    delete from t_article 
    where id in (
        select id from (
            select id from t_article 
            where (title,source) in (
                select title,source from t_article 
                group by title,source having count(*) > 1
            )
            and id not in (
                select id from (
                    select min(id) as id from t_article 
                    group by title,source having count(*) > 1
                ) as id
            )
        )as id    
    ) 
  • 相关阅读:
    nginx2
    nginx1
    将Tomcat设置为自动启动的服务最快捷方法
    keepalived VS zookeeper
    Linux CentOS 7 下 Apache Tomcat 7 安装与配置
    使用curl 命令模拟POST/GET请求
    netty3---传统IO,NIO,nettyIO
    个人或小型企业站该如何选择服务器?
    如果你不懂备案,那我简单点跟你说
    SAE Java相关问题小结
  • 原文地址:https://www.cnblogs.com/mjtabu/p/14277859.html
Copyright © 2011-2022 走看看