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
Is it possible in sql table to have more than one foreign key?
What are the fixed server level roles? : sql server security
What is sql azure database?
What is a field in a table?
What is the osql utility?
how to trace the traffic hitting a sql server? : Sql server database administration
How does index makes search faster?
How to invoke a trigger on demand?
Can we perform backup restore operation on tempdb?
How to provide column names in insert statements in ms sql server?
Define model database?
What gets stored inside msdb database?
How can you check the level of fragmentation on a table?
What is always encrypted?
Do you know the cursor types?