Reputation: 51
I have a table like this...
Name
------------
George
George
George
George
John
John
John
Paul
Paul
Arnold
.
and I need result with max number of duplicates. Forexaple max 2 duplicates.
Name
------------
George
George
John
John
Paul
Arnold
.
How I write the script? Thanks
Upvotes: 0
Views: 54
Reputation: 460208
You can use ROW_NUMBER
, for example:
WITH CTE AS
(
SELECT RN = ROW_NUMBER() OVER (PARTITION BY Name ORDER BY Name)
, Name
FROM dbo.Names
)
SELECT Name FROM CTE WHERE RN <= 2
Upvotes: 1