id        name       score
1          张三          80
2          李四          85
3          王五          90
4          张三          80
如何删除表中除ID不同,其它的列都相同的记录,如 name = 张三的记录,只能剩下一条

解决方案 »

  1.   

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

  2.   

    delete
     t
    from 
     tb t
    where
     id not in(select min(id) from tb where name=t.name)
      

  3.   

    delete a from tb a where (select count(1) from tb where Name=a.Name and ID<a.ID)>0
      

  4.   


    delete tb from tb t where id not in (select min(id) from tb where name = t.name and score = t.score)
    delete tb from tb t where id not in (select max(id) from tb where name = t.name and score = t.score)