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 are the results of running this script?
Distinguish between nested subquery and correlated subquery?
Do you know what is blocking?
What are the differences between INNER JOIN, LEFT JOIN and RIGHT JOIN in SQL Server?
Explain what is dbcc?
Explain the functionalities that views support?
How to convert a unicode strings to non-unicode strings?
What is implicit mode in sql server?
Thanks to some maintenance being done, the sql server on a failover cluster needs to be brought down. How do you bring the sql server down?
What is sql service broker?
Any one plz send me SQL Server Developer/DBA resume for 4 years experience
What is data compression? : sql server database administration
Can sql servers link to other servers?
How do I debug a stored procedure in sql server?
What are rows and columns?