TableOne
PersonId PersonScore
1 10
1 20
2 99
2 40
3 45
I need to get only those lines where PersonId appears more than once. Below is the result I want to achieve
PersonId PersonScore
1 10
1 20
2 99
2 40
I am using cte
;WITH cte AS (
SELECT *, ROW_NUMBER() OVER (PARTITION BY i.PersonId ORDER BY i.PersonId) AS [Num]
FROM TableOne i
)
SELECT *
FROM cte
WHERE cte.Num > 1
The problem is removing extra lines. It creates the first instance of any PersonId. Can anyone suggest a solution please
source
share