例如表Shirly里有id,spid字段,如果有spid相同的记录只留下一条,其余的删除。spid的内容不定,相同的记录数不定。
只要我把重复数据列出来,再改寫刪除不就可以了?
1、我先把想要删除的数据列出来,如下:
代码
1 SELECT * FROM Shirly where id<>(select max(id) from Shirly d where Shirly.spId =d.spId )
2 AND spId in (select spId from Shirly b GROUP BY spId HAVING COUNT(spId)>1)
2 AND spId in (select spId from Shirly b GROUP BY spId HAVING COUNT(spId)>1)
2、把SELECT * FROM 換成 Delete
3、圖:
所有數據:
重複項:
刪除: