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

What are the results of running this script?

659


Distinguish between nested subquery and correlated subquery?

751


Do you know what is blocking?

727


What are the differences between INNER JOIN, LEFT JOIN and RIGHT JOIN in SQL Server?

793


Explain what is dbcc?

777






Explain the functionalities that views support?

853


How to convert a unicode strings to non-unicode strings?

739


What is implicit mode in sql server?

738


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?

705


What is sql service broker?

736


Any one plz send me SQL Server Developer/DBA resume for 4 years experience

2370


What is data compression? : sql server database administration

700


Can sql servers link to other servers?

750


How do I debug a stored procedure in sql server?

724


What are rows and columns?

717