I wrote a query below to get duplicate clients using Row_Number () in SQL Server.
Cust_PKID ---------------+ CustomerID ----------------- + MobileNo
1 | A00001 | 9000477444
2 | A00002 | 9000477444
3 | A00003 | 9000477444
Query: -
Select TMP.CustID
From
(
Select CustomerID CustID,
Row_Number() Over(Partition By MobileNo Order By (Select Null)) As RowNo
From dbo.Customers
) TMP
Where TMP.RowNo > 1
Output: -
Cust_PKID ---------------+ CustomerID ----------------- + MobileNo
2 | A00002 | 9000477444
3 | A00003 | 9000477444
How can I get entries, including the first RowNo entry, in one ad?
source
share