各位好。现在有一张表的某些行的各字段值都是一模一样的,如何写一个delete语句来去重呢?

解决方案 »

  1.   

    这个在baidu里面一搜  很多吧?http://apps.hi.baidu.com/share/detail/9249849 
      

  2.   

    delete from table_name t where rowid<(select max(rowid) from table_name a where a.field1=t.field1 and a.field2=t.field2....);
      

  3.   


    --参考:
    delete from table_name a
    where not exists(
          select 1
          from table_name b
          where a.id = b.id --表的自连接条件
            and a.col < b.col --这个是最重要的条件,它确定了保存那条数据
          )
      

  4.   

    一般采用伪列rowid来删除重复数据比较好
      

  5.   

    根据rowid 来删除rowid比最小值更大的。
    delete from tab a  where rowid>(select min(rowid) from  tab  b  where a.id=b.id and ....)