Solved

how to delete duplicate rows in db2 server

Posted on 2011-02-28
2
993 Views
Last Modified: 2012-05-11
i want the syntax to delete  the duplicate records of my table  in db2.
0
Comment
Question by:Sam2009
2 Comments
 
LVL 37

Accepted Solution

by:
momi_sabag earned 250 total points
ID: 34997501
assuming you have some pk column, and another column you can use to choose which record you want to keep, you can do:


with a as (
  select *, row_numbe() over(partition by pk_column1,pk_column2 order by case when value_column='value to keep' then -1 else 1 end asc) rown
 from your_table
)
delete from a where rown > 1
0
 

Author Comment

by:Sam2009
ID: 35043783
hello,

it worked!

thanks
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

November 2009 Recently, a question came up in the DB2 forum regarding the date format in DB2 UDB for AS/400.  Apparently in UDB LUW (Linux/Unix/Windows), the date format is a system-wide setting, and is not controlled at the session level.  I'm n…
Recursive SQL in UDB/LUW (it really isn't that hard to do) Recursive SQL is most often used to convert columns to rows or rows to columns.  A previous article described the process of converting rows to columns.  This article will build off of th…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now