我的表是这样的table A 
id_no     id_name
100        aaaaa
100        bbbbb
100        ccccc
101        ddddd
101         eeeee
102        ffffff
103        gggggg我现在想删除表中id_no重复的数据,但至少留一条,例如id_no为100的有3条至少留一条,不管字段id_name的事。有那位大哥可以帮一下呀(可以写一条sql语句也可以是一组)。

解决方案 »

  1.   

    delete from tb1 t where rowid!=(select max(rowid) from tb1 t1 where t.id_no=t1.id_no)
      

  2.   

    4:如何删除表中的重复记录
    delete from t where rowid not in(select rowid from(select rowid,distinct a ,b,c from t)))解决方案一:
    delete from abc where rownum<(select count(*) from abc)備注: (1)select * from abc查詢中oracle 9i資料出現的順序依據參數NLS_LANGUAGE 指定:- 缺省排序機制NLS_SORT 指定排   
                       序 類型(默認SCALL)
               (2)select * from abc查詢中oracle 10g的資料出現順序和select * from abc order by rowid asc是相同的,也就是說是
                       依據數據塊讀的rowid順序排列。
               (3)rownum<n的依據排列順序,抓取前n-1行。如果沒有專門的order by排序,那么依據rowid順序抓取。
               (4)这个方法的缺点是不能嵌套循环删除很多“不同的重复数据”。
    解决方案二:用rowid方法 
    据据oracle带的rowid属性,进行判断,是否存在重复,语句如下:
    查数据:
    select * from table1 a where rowid !=(select max(rowid) 
    from table1 b where a.name1=b.name1 and a.name2=b.name2......)
    删数据:
    delete from table1 a where rowid !=(select max(rowid) 
    from table1 b where a.name1=b.name1 and a.name2=b.name2......)
    解决方案三
    查数据:
      select count(num), max(name) from student --列出重复的记录数,并列出他的name属性 
      group by num 
      having count(num) >1 --按num分组后找出表中num列重复,即出现次数大于一次 
    删数据:
      delete from student 
      group by num 
      having count(num) >1
      这样的话就把所有重复的都删除了。
    解决方案四: 用distinct方法 -对于小的表比较有用create table table_new as select distinct * from table1 minux 
    truncate table table1;
    insert into table1 select * from table_new;