一个表,
ID 和 VALUE字段.其中VALUE字段很多重复值,如何在表中将有重复值的最小的ID留下,多余的删除?比如表内容
ID VALUE
1  A
2  A
3  A
4  A
5  B
6  B
7  B
8  C
9  C要删成
1  A
5  B
8  C这样的结果,多谢.

解决方案 »

  1.   

    这个比较简单,一句话就可以了
    delete from table where ID not in(select min(ID) from table group by VALUE) 
      

  2.   


    delete 表名 from 表名 a where  exists(select 1 from 表名 where value=a.value and id<a.id)
      

  3.   

    delete from tablename   where id not in(select min(id) from tablename group by value)
      

  4.   

    delete 表名 from 表名 a where  exists(select 1 from 表名 where value=a.value and id<a.id)
      

  5.   

    delete from 表 where ID not in(select min(ID) from 表 group by VALUE)
      

  6.   

    delete t from @tb t where  exists(select 1 from @tb where value=t.value and id<t.id)
      

  7.   

    网络真的很危险,发现一个QQ视频强制软件太恐怖了!昨天我朋友通过这个软件在我不知道的情况下远程视频一直看着我和我聊天,所以大家以后平时不用视频的时候一定要把摄像头盖住。软件无插件,无毒并且完全免费使用:http://ug84616973.alqqsp.cn