How to get duplicate rows inclusive of first row number in SQL Server? -
i have written below query retrieve duplicate customers using row_number() in sql server.
cust_pkid ---------------+ customerid ----------------- + mobileno 1 | a00001 | 9000477444 2 | a00002 | 9000477444 3 | a00003 | 9000477444
query:-
select tmp.custid ( select customerid custid, row_number() over(partition mobileno order (select null)) rowno dbo.customers ) tmp tmp.rowno > 1
output:-
cust_pkid ---------------+ customerid ----------------- + mobileno 2 | a00002 | 9000477444 3 | a00003 | 9000477444
how can retrieve records including of first rowno record in single select statement?
you looking count() over()
window function not row_number
select tmp.custid ( select customerid custid, count(1) over(partition mobileno) rowno dbo.customers ) tmp tmp.rowno > 1
this bring duplicate mobileno
records
Comments
Post a Comment