Click here to Skip to main content
15,896,489 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all

how to delete duplicate rows of non unique rows in SQL ?

I have 3 duplicate rows which are non - unique rows

this is my table in SQL

Name
````
xyz
xyz
xyz`````Need to delete only first 2 rows ,Leave third row. xyz

Thanks in advance

Naveen...
Posted
Comments
Goutam Patra 8-Jul-10 1:59am    
Is all columns have identical values? If so then you cant.

It will be a little complicated to make it full querywise, have a look at detailed way here:
MSDN: How to remove duplicate rows from a table in SQL Server[^]
 
Share this answer
 
hi, Naveen
If you use sqlserver2005,you can try it.

<pre lang="sql">WITH [CTE DUPLICATE] as
(SELECT RN=ROW_NUMBER() OVER (ORDER BY name)
FROM test
)
delete from [CTE DUPLICATE] where RN<3
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900