I am needing to get the row id of rows which have duplicate
Select Name from table1 group by Name having count(1) > 1
table1
ID | Name | ClientID
----------------------------
01 | John | 01
02 | Sam | 01
03 | Sue | 01
04 | John | 02
05 | John | 01
the only problem is that it will only return the Name and not the ID of the column as I have multiple clients on the same table and I don't want to count the names from the other clients as duplicates.
So is there a way to find duplicate data in a table and return the ids of the rows so that I can then use those id's in another query?
Answer I went with modified
Thank you every one for the answers I went with this one which is a modification of the one I marked as the answer.
select t1.*
from (select count(*) over (partition by entityname) as cnt ,t1.*
from table1 t1 where ClientID = 1
) t1
where cnt > 1 and ClientID = 1 order by cnt;