我的表里面有存在4万多的重复数据,请问我怎么把他们去除掉
(例如:一条数据有4条重复的记录,我希望除掉重复3条)
请问应当如何实现?

解决方案 »

  1.   

    delete from tab a where a.rowid!=(select max(rowid) from tab b where a.id=b.id and a.name=b.name); delete from tab a where exists(select 1 from tab b where a.id=b.id and a.name=b.name and a.rowid>b.rowid);
    delete from tab where rowid not in(select max(rowid) from tab group by id,name);
      

  2.   

    delete from tab a where a.rowid!=(select max(rowid) from tab b where a.id=b.id and a.name=b.name);
      

  3.   


    我用的第一句好像有误差啊~我一共有18万数据,用了distinct看到实际去重复后的数据应该只有14万。但是用你的第一个写法统计一下发现要删除的数据居然有7万多,应该是多删了一部分!
    我的表里面有一个fld_mobile字段主要就是很多数据这个字段重复了
      

  4.   

    如果是你确定某个字段fld_mobile重复,这样:delete from tab where rowid !=(select max(rowid) from tab group by fld_mobile);
      

  5.   

    对,我就是这样写的:
    (1)select count(fld_mobile) from tab --统计出一共有187850条数据
    (2)select count(distinct(fld_mobile)) from from tab --除掉重复后统计出来有141470条数据
    (3)slect count(*) from tab where rowid not in(select max(rowid) from tab group by fld_mobile);
    --用你说的这种写法发现需要删除的数据有76956条两组数据有出入,去掉重复后有141470.如果按这种删除76956的话应该就会多删除数据了!不知道为什么会有这种数据上的差异??
      

  6.   

    不对啊,如果你很多数据都是fld_mobile字段重复,那么其它字段数据重复不呢?如果用delete from tab where rowid !=(select max(rowid) from tab group by fld_mobile);来删除,就会只剩下fld_mobile字段不重复的数据,那么其它字段就算不重复也删除了,你一定要考虑清楚!到底什么才是你要删除的重复数据!
      

  7.   

    是不是你字段fld_mobile有空值?
    select count(1) from  tab where fld_mobile is null你查看下呢