sql去重复

  • 假设存在一个主键ID,Name为重复列,下面这句可以查出所有的没有重复的数据:  

  • select * from 表 as a where ID=(select min(ID) from 表 where Name=a.Name) 。

  • 根据上面这句就可以删除所有重复项的数据:                                                    

  • delete from 表 where ID not in(select ID from 表 as a where ID=(select min(ID) from 表 where Name=a.Name))。

   执行:select * from T_COM_SMSCLog as a where ID=(select min(ID) from T_COM_SMSCLog  where LoginName=a.LoginName and SendType=2 and IsSuccess!=1 and SMSId=505)

posted @ 2018-05-29 13:03  AAABONE  阅读(121)  评论(0编辑  收藏  举报