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 6890809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:19:45+00:00 2026-05-27T06:19:45+00:00

I know this might be redundant but I have had the same query running

  • 0

I know this might be redundant but I have had the same query running for almost 3 days and before I kill it, I would like to get a community sanity check.

DELETE
FROM    mytble
WHERE   ogc_fid NOT IN
    (SELECT     MAX(dup.ogc_fid)
        FROM        mytble As dup
        GROUP BY    dup.id)

mytble is the name of the table, ogc_fid is the name of the unique id field and id is the name of the field that I want to be the unique id. There are 41 million records in the table and indexes are built and everything so I am still a bit concerned about why its taking so long to complete. Any thoughts on this?

  • 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-05-27T06:19:46+00:00Added an answer on May 27, 2026 at 6:19 am

    If I understood correctly, you want to delete all the records for which a record with the same dup_id
    (but with a higher ogc_fid) exists. And keep only those with the highest ogc_fid.

    -- DELETE -- uncomment this line and comment the next line if proven innocent.
    SELECT COUNT(*)
      FROM   mytble mt
     WHERE   EXISTS (
      SELECT *
        FROM mytble nx
       WHERE nx.dup_id = mt.dup_id    -- there exists a row with the same dup_id
         AND nx.ogc_fid > mt.ogc_fid  -- , ... but with a higher ogc_fid 
    );
    

    With an index on dup_id (and maybe on ogc_id) this should run maybe a few minutes for 41M records.

    UPDATE: if no indexes exist, you could speed up the above queries by first creating an index:

     CREATE UNIQUE INDEX sinterklaas ON mytble (dup_id, ogc_id);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this might have been asked a thousand times before, but I can't
I know this might have been probably asked before but through out the net
I know this might be a long shot, but here it goes. I have
I know this might sound silly but I have no idea how to do
I know this might be a common question but I have tried to search
I know this might be a simple question but I have to make sure
I know this might sound like a dumb question, but I have looked every
I know this might ma a simple question, it must have been answered before
Know this might be rather basic, but I been trying to figure out how
I know this might be a no-brainer, but please read on. I also know

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.