SqlServer删除重复数据保留一条
1、查询出重复的数据,Id只保留其中一个
SELECT MIN(Id) Id,Name FROM dbo.City GROUP BY Name HAVING COUNT(1) > 1
2、然后使用删除时Join上面的表
DELETE C FROM City C JOIN ( SELECT MIN(Id) Id,Name FROM dbo.City GROUP BY Name HAVING COUNT(1) > 1 ) TMP ON C.Name = TMP.Name AND C.Id <> TMP.Id