Loading ...

Selecting duplicate rows from a table in sql server | CodeAsp.Net

Selecting duplicate rows from a table in sql server

 /5
0 (0votes)

This example shows on how to  get all duplicate  rows from a table for this I’m going to create a Table with two column  and inserting some distinct & duplicate rows in it and then write query to display all duplicate records .

Step1:

CREATE TABLE Employ_Salary_Record
( EmployeeName Nvarchar(50) , Salary int)

Step2:

Insert into Employ_Salary_Record values('a1',11000)
Insert into Employ_Salary_Record values('a1',11000)
Insert into Employ_Salary_Record values('a1',11000)
Insert into Employ_Salary_Record values('a1',11000)
Insert into  Employ_Salary_Record values('a1',11000)
Insert into Employ_Salary_Record values('a9',1000)
Insert into Employ_Salary_Record values('a9',1000)
Insert into Employ_Salary_Record values('a9',1800)
Insert into Employ_Salary_Record values('a8',1800)
Insert into Employ_Salary_Record values('a8',18000)
Insert into Employ_Salary_Record values('a6',1000)

Step3:

Select EmployeeName,Salary , count(*) as RowsCount from Employ_Salary_Record group by EmployeeName,Salary having count(*)>1

Executing the above query will show this output:

 EmployeeNameSalaryRowsCount
1a910002
2a111000
5

I hope you will find this example useful

Comments (no comments yet)

Top Posts