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
What is the user of Primary key?
Why de-normalization required?
What are extended events in sql server?
What is ms sql server triggers?
Define the one-to-one relationship while designing tables.
What is report snapshot?
Explain how you can deploy an SSRS report?
What happens if the update subquery returns multiple rows in ms sql server?
What is the return type of executeupdate ()?
How to execute stored procedure in select statement sql server?
What do you mean by collation recursive stored procedure?
You are doing log shipping due to some reasons it is failing. How you will proceed from there
What is the difference between locking and multi-versioning?
How do you rename a table in sql server?
Detail about query optimizer?