SQL Server 删除重复数据只保留一条

DELETE FROM Bus_TerminalMessage_Keywords WHERE Content IN (select Content from Bus_TerminalMessage_Keywords group by Content having count(Content) > 1)
AND
ID NOT IN (select min(Id) from Bus_TerminalMessage_Keywords group by Content having count(Content)>1)

  

第一个条件是找到重复的数据,第二个条件是在重复的数据中保留一条。两个条件取交集就能删除重复数据了

上一篇:mysql对String类型的数字值排序


下一篇:day 77 基于form组件的注册功能