question

naveen 1 1 avatar image
naveen 1 1 asked

how to delete duplicate rows of non unique rows

hi all ,

I have 3 duplicate rows which are non - unique rows

this is my table in SQL

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

Thank in advanve

Naveen

sql-server-2005
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Squirrel 1 avatar image
Squirrel 1 answered

basically something like this

delete d            
from               
(            
    select *, row_no = row_number() over (partition by somecol order by anothercol)            
    from   sometable            
) d            
where d.row_no <> 1            

specify the column name that you want to be as unique in the partition by

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.