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)

猜你喜欢

转载自www.cnblogs.com/yidengbone/p/9104509.html
今日推荐