在Oracle中怎么删除重复的行,但要保留一条记录。

解决方案 »

  1.   

     1.如果有ID字段,就是具有唯一性的字段   
        
      delect   table   where   id   not   in   (   
        
          select   max(id)   from   table   group   by   col1,col2,col3...   
      )   
      group   by   子句后跟的字段就是你用来判断重复的条件,如只有col1,那么只要col1字段内容相同即表示记录相同2.没有ID字段,用rowid
    delete from table where rowid in (select a.rowid from table a, table b 
    where a.rowid>b.rowid and a.col1=b.col1 and a.col2 = b.col2 and ...)
      

  2.   

    delete table where rowid not in (select max(rowid) from table group by col1,col2,...,coln);
      

  3.   

    delete tb a
    where a.rowid > (select min(b.rowid)
    from tb b
    where b.xx = a.xx)
      

  4.   

    delete 表名 where rowid not in (select max(rowid) from 表名 group by 列名);(注这里的列名就是你根据那个列判断重复的,可以为多列)
      

  5.   

    delete from table where rowid in (select a.rowid from table a, table b  
    where a.rowid>b.rowid and a.col1=b.col1 and a.col2 = b.col2 and ...)
      

  6.   

    使用rowid时最后的解决办法,表中每行记录的rowid都是唯一的
    delete from table_A  a
       where a.rowid < (select max(b.rowid) 
                          from table_A  b 
                        where a.column1 = b.column1
                          and a.column2 = b.column2
                          ...   --有多少列就写多少列,方法同上
                        );