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

  • Home
  • SEARCH
  • 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 6569689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:39:48+00:00 2026-05-25T14:39:48+00:00

so i have two tables, one is RAWtable and the other is MAINtable, I

  • 0

so i have two tables, one is RAWtable and the other is MAINtable, I have to get the latest groupID if there
are more than one records exist (comparing same name, code). For example, I have this on RAWtable:

id  groupid     name        code
1   G09161405   Name1       Code1
2   G09161406   Name1       Code1

the two records should be treated as one and should return this value only:

id  groupid     name        code
2   G09161406   Name1       Code1

This row is the only row that shiuld be inserted in the main table. Provided returning the latest GroupID (the groupid is the combination of date and time)

I’ve tried this but its not working:

SELECT MAST.ID, MAST.code, MAST.name FROM RAWtable AS MAST INNER JOIN 
(SELECT code, name, grouid,id FROM RAWtable AS DUPT GROUP BY code, name, groupid,id HAVING COUNT(*) >= 2) DUPT
 ON  DUPT.code =MAST.code and DUPT.name =MAST.name where dupt.groupid >mast.groupid 

how can i do this? thanks a lot.

  • 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-25T14:39:49+00:00Added an answer on May 25, 2026 at 2:39 pm
    select R.id,
           R.groupid,
           R.name,
           R.code
    from (select id, 
                 groupid, 
                 name, 
                 code,
                 row_number() over(partition by name, code order by groupid desc) as rn
          from RawTable       
         ) as R
    where R.rn = 1     
    

    Or if you don’t have row_number()

    select R1.id,
           R1.groupid,
           R1.name,
           R1.code
    from RawTable as R1
      inner join (  
                  select name, code, max(groupid) as groupid
                  from RawTable
                  group by name, code
                 ) as R2
        on R1.name = R2.name and
           R1.code = R2.code and
           R1.groupid = R2.groupid
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables(InnoDB) one with 15 million records and the other with 14
I have two tables : one table it matchs and the other is teams.
I have two tables, one is for news and the other one is for
I have two tables one being a copy of the other. (I have to
I have two tables: one has a datetime column, the other has a date
I have two tables one called details and the other called c_details. Both tables
I have two tables one has a three column composite key. The other needs
I have two tables one is heardt and other one is jud In heardt
I have two tables: one with emails and the other table with domains. Table1
I have two tables: one hostgroup_host and the other one hostgroups. The hostgroups represents

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.