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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:07:09+00:00 2026-05-13T14:07:09+00:00

I have a table with fields (simplified): id, fld1, fld2, fld3. id is a

  • 0

I have a table with fields (simplified):

id, fld1, fld2, fld3.

id is a numeric primary key field.

There are duplicates: id differs but fld1, fld2 and fld3 are identical over 2 or more rows. There are also entries where the values occur only once, i.e. non-duplicates, of course.

Of each set of duplicate entries, I want to retain only the entry with the highest ID. I was planning to first list the doomed rows and then to delete them.

My first stab at it was this:

SELECT * FROM tab1 t1 WHERE EXISTS (
  SELECT COUNT(*) FROM tab1 t2
  WHERE t1.fld1 = t2.fld1 AND t1.fld2 = t2.fld2 AND t1.fld3 = t2.fld3
    AND t1.id < MAX(t2.id)
  HAVING COUNT(*) > 1
  GROUP BY t2.fld1, t2.fld2, t2.fld3)

But (in Oracle) I’m getting a Missing right parenthesis error message. I think this needs a new approach altogether, but my SQL-fu is not up to the task. Help appreciated!


Edit:

With ‘real’ data fields:

select x.leg_id, x.airline_des, x.flight_nr, x.suffix, x.flight_id_date, x.lt_flight_id_date
from fdb_leg x
join ( select max(t.leg_id) 'max_id', 
t.airline_des, t.flight_nr, t.suffix, t.flight_id_date, t.lt_flight_id_date
from fdb_leg t
group by t.airline_des, t.flight_nr, t.suffix, t.flight_id_date, t.lt_flight_id_date
having count(*) > 1) y on y.max_id > x.leg_id
and y.airline_des = x.airline_des and y.flight_nr = x.flight_nr and y.suffix = x.suffix
and y.flight_id_date = x.flight_id_date and x.lt_flight_id_date = y.lt_flight_id_date

Response is:

ORA-00923: FROM keyword not found where expected

  • 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-13T14:07:10+00:00Added an answer on May 13, 2026 at 2:07 pm

    Oracle 9i+, Using WITH:


    To get the list of doomed entries, use:

    WITH keepers AS (
       SELECT MAX(t.id) 'max_id',
              t.fld1, t.fld2, t.fld3
         FROM TABLE_1 t
     GROUP BY t.fld1, t.fld2, t.fld3
       HAVING COUNT(*) > 1)
    SELECT x.id,
           x.fld1, x.fld2, x.fld3
      FROM TABLE_1 x
      JOIN keepers y ON y.max_id > x.id
                    AND y.fld1 = x.fld1
                    AND y.fld2 = x.fld2
                    AND y.fld3 = x.fld3
    

    Non-WITH Equivalent:


    To get the list of doomed entries, use:

    SELECT x.id,
           x.fld1, x.fld2, x.fld3
      FROM TABLE_1 x
      JOIN (SELECT MAX(t.id) 'max_id',
                   t.fld1, t.fld2, t.fld3
              FROM TABLE_1 t
          GROUP BY t.fld1, t.fld2, t.fld3
            HAVING COUNT(*) > 1) y ON y.max_id > x.id
                                  AND y.fld1 = x.fld1
                                  AND y.fld2 = x.fld2
                                  AND y.fld3 = x.fld3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have payment table fields update reason and amount & total field are change
I have a table with fields user_id and votes . The votes field is
I have Access table with fields, in which there is some data and path
Simplified scenario, I have a table with the following fields/values: ID value 1 '12345'
I have the following models (simplified leaving all other fields out, focusing on primary
I have a table within a form. The table contains some form fields, but
I have my Table structure like this :: ATT_Table : Fields - Act_ID, Assigned_To_ID,
I have table A with fields user1 and user2 and table B with user3
I have a table the fields are Id1 , ID2 , Points1 , Points2
So I have a table containing fields description and short_description . I imported these

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.