Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1013
  • Last Modified:

how to delete duplicate rows in db2 server

i want the syntax to delete  the duplicate records of my table  in db2.
0
Sam2009
Asked:
Sam2009
1 Solution
 
momi_sabagCommented:
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
 
Sam2009Author Commented:
hello,

it worked!

thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now