Solved

how to delete duplicate rows in db2 server

Posted on 2011-02-28
2
1,001 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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
DB2 join tables across schemas 5 574
Check file/object size on AS400 3 181
Configuration Assistant in DB2 10.1 3 84
AS400 QAOSDIAJRN / APYJRNCHG Processing 5 18
Recursive SQL in UDB/LUW (you can use 'recursive' and 'SQL' in the same sentence) A growing number of database queries lend themselves to recursive solutions.  It's not always easy to spot when recursion is called for, especially for people una…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

840 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