I have a table EMP in which the values will be like this
EmpId Ename Sal DeptId
11 Ram 10000 10
11 Ram 10000 10
22 Raj 20000 20
22 Raj 20000 20
33 Anil 15000 30
33 Anil 15000 30
I want to delete only duplicate Rows. After Delete I want
the output like this
EmpId Ename Sal DeptId
11 Ram 10000 10
22 Raj 20000 20
33 Anil 15000 30
Answer Posted / siddharth
DECLARE @int as int
DECLARE @cnt as int
WHILE EXISTS (SELECt top 1 EmpId from Emp group by EmpId having count(EmpId)>1 order by EmpId)
Begin
SELECT top 1 @int=EmpId,@cnt=Count(EmpId) from Emp group by EmpId having count(EmpId)>1 order by EmpId
Delete top (@cnt-1) from Emp where EmpId = @int
End
Select EmpId,Ename,Sal,DeptId from Emp order by EmId
| Is This Answer Correct ? | 4 Yes | 0 No |
Post New Answer View All Answers
Explain boyce and codd normal form(bcnf)?
Explain error handling in ssis?
What is an indexing technique?
What it means to be triggered?
What are various ways to enhance the ssrs report?
Can we call future method from trigger?
What is the difference between writing data to mirrored drives versus raid5 drives
What is system stored procedures?
Do you know how to implement service broker?
Can two tables share the same primary key?
What is role playing dimension with two examples? : sql server analysis services, ssas
What is fill factor and pad index?
What is an entity-relationship diagram (erd)?
Explain transaction server isolation?
Distinguish between commit and rollback?