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

How to insert multiple rows with a subquery?

532


What is an index in a database?

538


What is function of master database?

94


How to integrate the ssrs reports in application?

544


You want to use bids to deploy a report to a different server than the one you chose in the report wizard. How can you change the server url?

110






How do you rename a table in sql server?

496


What is the difference between count and distinct count?

468


What are the types of database schema? : sql server analysis services, ssas

601


What is database architecture? : SQL Server Architecture

555


How to see the event list of an existing trigger using sys.trigger_events?

573


What is after dml trigger?

577


What are information schema views?

559


What do you mean by cardinality?

497


What is a Join and explain its types?

588


Tell me in brief how sql server enhances scalability of the database system?

536