有个 数据库 有 大量的数据大概600万条 
里面有大量的重复数据 
如何利用SQL语句来把重复的数据消除 
相同的 数据只保留一条?

解决方案 »

  1.   

    delete from Ytab where rowid not in (select max(rowid) from Ytab  group by 字段);
      

  2.   

    delete from tablename a  where rowid<>(select min(rowid) from tablename b 
    where a.id=b.id goup by a.id)
      

  3.   

    这个问题好像都回答过了,
    使用分析函数的RowNum就可以,
    楼主给出表结构,给你完整SQL。
      

  4.   

    补充说明:数据库表中有及个字段 
    其中有个是IP字段  
    大量的数据中IP数据有不少重复 现在想把记录中IP相互重复的消掉,只保留一条 数据库名 ipinfo表中大概有500万条数据 
    重复的有20万条 想得到的不重复的(500-20)万条数据
      

  5.   

    delete from ipinfo where rowid not in (select max(rowid) from ipinfo group by IP);
      

  6.   

    说个清楚的:表名ipinfo  
    ID    ip         msk  
    1  192.168.1.1   24  
    2  192.168.1.2   24  
    3  192.168.1.1   23  
    4  192.168.1.1   26  不管msk字段是什么 就看ip的相同情况   错做结果:  
    ID    ip         msk  
    1  192.168.1.1   24  
    2  192.168.1.2   24  我在网上找的资料 
    看看这样些对不对: 
    delete from ipinfo a where a.id <>(select min(id) from ipinfo where ip=a.ip) 如果是对的 不理解a是什么意思  
    以前学 SQL语句时没碰到这种写法
      

  7.   

    谁给我解释下:
    delete from ipinfo a where a.id  <>(select min(id) from ipinfo where ip=a.ip)  嘿嘿
    我不太理解
      

  8.   

    delete from tablename where 条件=条件
                               and rowid <>(select max(rowid) from tablename where 条件=条件)
      

  9.   

    a实际上就是表ipinfo的别名~~a.id你可以理解为ipinfo.id~~
      

  10.   

    delete from ipinfo a where a.id  <(select max(id) from ipinfo where ip=a.ip)  
    思想都一样,都是先找到保留的记录,在删除其他数据记录