Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8538139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:04:36+00:00 2026-06-11T11:04:36+00:00

I have mistakenly loaded duplicate files into a database table (IBM DB2 v9.7). I

  • 0

I have mistakenly loaded duplicate files into a database table (IBM DB2 v9.7). I need to delete the duplicate records without deleting valid data.

Initially, I though of HAVING count(*) > 1 as the solution to my problem but this will not work. Our supplier produces parts with modified specs so a file may be loaded more than once with valid data.

I know a few things:

  1. the date range for my duplicate records: between ‘2012-08-27’ and
    ‘2012-09-02’
  2. the attributes to use to validate data

This is my SQL code to identify the dupes:

SELECT CAST(ENDDATE AS DATE) ENDDATE,CAST(LOADEDON AS DATE),SUBSTR(SITEID,1,20) SITEID,SUBSTR(LOCATIONNAME_1,1,20),SUBSTR(RID,1,15),COUNT(RID) FROM AUTOMATION WHERE CAST(ENDDATE AS DATE) BETWEEN '2012-08-27' AND '2012-09-02' GROUP BY CAST(ENDDATE AS DATE),CAST(LOADEDON AS DATE),SUBSTR(SITEID,1,20),SUBSTR(LOCATIONNAME_1,1,20),SUBSTR(RID,1,15) ORDER BY 5 ASC FOR FETCH ONLY WITH UR

EDIT: set of columns that can be used to specify a duplicate are RID,LOADEDON and FILENAME (not shown here).

This is a sample output

08/29/2012 09/05/2012 JGS Memphis          JGS Memphis          029369751671            518
09/01/2012 09/05/2012 Reynosa              Reynosa              029054883474            521
08/29/2012 09/05/2012 JGS Memphis          JGS Memphis          028881223425            522

I want to delete all the duplicate records in the timeframe ‘2012-08-27’ AND ‘2012-09-02’ without deleting the records that are loaded N times for legit reasons.

Note: the table does not have a primary key (like Rowid in MS Sqlserver, for instance)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T11:04:38+00:00Added an answer on June 11, 2026 at 11:04 am

    I can’t quite tell which set of columns specifies a duplicate. The following assumes that it is the columns in your sample output:

    delete from (select t.*,
                        row_number() over (partition by enddate, loadedon, siteid order by loadedon desc) as seqnum
                 from automation t
                ) t
    where seqnum > 1
    

    This uses row_number() to assign sequential numbers and deletes all but the first row, guaranteeing that one stays in the database.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a few files that were part of an update that were mistakenly
I have an iframe that is being loaded into external sites of which I
Hi mistakenly I have deleted my MySQL database from Windos XP based PC (this
I mistakenly added files to Git using the command: git add myfile.txt I have
One row in a table got mistakenly overwritten. I have a backup of the
have 2 questions : A computer with 32-bit address uses 2-level page table (9
I have mistakenly sent API username and password in bitbucket code, how do i
I have a table which contains sales order data (order number, product number, sales
I have a ViewController (with a MKMapView) which is pushed into, because of the
I have the models User and Group, and the join table Membership which uses

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.