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 / aashish lad

-- Here Temp1 is Temporary Table So it will take All records
-- From Mytable With RowNumbar column
-- We can Delete the Record from


SELECT ROW_NUMBER() OVER(PARTITION BY empid ORDER BY empid)
AS RowNumber, * into #temp1 FROM mytable

DELETE FROM #temp1 WHERE RowNumber> 1

INSERT INTO mytable

SELECT * FROM #temp

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the user of Primary key?

579


Why de-normalization required?

569


What are extended events in sql server?

506


What is ms sql server triggers?

532


Define the one-to-one relationship while designing tables.

509






What is report snapshot?

99


Explain how you can deploy an SSRS report?

106


What happens if the update subquery returns multiple rows in ms sql server?

586


What is the return type of executeupdate ()?

517


How to execute stored procedure in select statement sql server?

529


What do you mean by collation recursive stored procedure?

588


You are doing log shipping due to some reasons it is failing. How you will proceed from there

1545


What is the difference between locking and multi-versioning?

529


How do you rename a table in sql server?

489


Detail about query optimizer?

609