Remove duplicate records except the first record in SQL
问题 I want to remove all duplicate records except the first one. Like : NAME R R rajesh YOGESH YOGESH Now in the above I want to remove the second "R" and the second "YOGESH". I have only one column whose name is "NAME". 回答1: Use a CTE (I have several of these in production). ;WITH duplicateRemoval as ( SELECT [name] ,ROW_NUMBER() OVER(PARTITION BY [name] ORDER BY [name]) ranked from #myTable ORDER BY name ) DELETE FROM duplicateRemoval WHERE ranked > 1; Explanation : The CTE will grab all of