Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how to delete duplicate rows in db2 server

Posted on 2011-02-28
2
Medium Priority
?
1,009 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 1000 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

972 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