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 buffer cash in sql server?
Why do you need a sql server?
what are user defined datatypes? : Sql server database administration
What is user-defined multi-statement table-valued function?
What are the properties of the transaction?
What are ddl triggers and types of ddl trigger?
Can you leave a union at any time?
What are the parts of a function?
What do you understand by recursive stored procedure?
What are the types of joins in sql?
What is inner join? Explain with an example?
What is indexing explain it with an example?
What is the default schema of your login session in ms sql server?
Define a cross join?
What are the aggregate and scalar functions?