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
How to insert multiple rows with a subquery?
What is an index in a database?
What is function of master database?
How to integrate the ssrs reports in application?
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?
How do you rename a table in sql server?
What is the difference between count and distinct count?
What are the types of database schema? : sql server analysis services, ssas
What is database architecture? : SQL Server Architecture
How to see the event list of an existing trigger using sys.trigger_events?
What is after dml trigger?
What are information schema views?
What do you mean by cardinality?
What is a Join and explain its types?
Tell me in brief how sql server enhances scalability of the database system?