Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1010
  • 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

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

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