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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:57:03+00:00 2026-06-04T08:57:03+00:00

I have 2 tables NAME +—-+———+ | id | name | +—-+———+ | 1

  • 0

I have 2 tables

   NAME
   +----+---------+
   | id |   name  |
   +----+---------+
   |  1 |   ABC   |
   |  2 |   CCC   |
   +----+---------+

   TBL_STATUS
   +----+-----------+--------+
   | id |  name_id  | status |
   +----+-----------+--------+
   |  1 |     1     |   KU   |
   |  2 |     1     |   HP   |
   |  3 |     1     |   HK   |
   |  4 |     2     |   KU   |
   |  5 |     2     |   HP   |
   +----+-----------+--------+

I select and join together (INNER JOIN) this 2 tables.
This is the result for my query.

   +---------+--------+
   |   name  | status |
   +---------+--------+
   |   ABC   |   HK   |
   |   ABC   |   HP   |
   |   ABC   |   KU   |
   |   CCC   |   HP   |
   |   CCC   |   KU   |
   +---------+--------+

Each name can have 3 status. HK, HP, or KU.
I want only a row for each name for the latest status.
For example:

   +---------+--------+
   |   name  | status |
   +---------+--------+
   |   ABC   |   HK   |
   |   CCC   |   HP   |
   +---------+--------+

Status priority should display with HK first (if any),
then if no HK display HP, and so on..

  • 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-04T08:57:04+00:00Added an answer on June 4, 2026 at 8:57 am

    You are on the right tracks with your final output of

       +----+---------+--------+
       | id |   name  | status |
       +----+---------+--------+
       |  1 |   ABC   |   HK   | -- Need to remove
       |  2 |   ABC   |   HP   | -- Need to remove
       |  3 |   ABC   |   KU   |
       |  5 |   CCC   |   HP   | -- Need to remove
       |  6 |   CCC   |   KU   | 
       +----+---------+--------+
    

    you just need to limit this to the max ID for each name, which is achieved in the below using an INNER JOIN on an aggregate query.

    SELECT  Name, Status
    FROM    Name
            INNER JOIN tbl_Status
                ON tbl_Status.Name_ID = Name.ID
            INNER JOIN
            (   SELECT  MAX(ID) AS MaxStatusID
                FROM    Tbl_Status
                GROUP BY Name_ID
            ) MaxStatus
                ON MaxStatusID = tbl_Status.ID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hi i have tables like this: Persons: person_id, name then i have many langauge
Need help figuring this out. I have two tables user ---- name skills (comma
I have two tables User id name Result id user_id score created_at Every hour
This has been driving me mad. I have three tables: items ID name type
I have two tables Users (name, email, password, instance_id, etc...) example: james bond, james@abc.com,
I have several tables: lecturer(id,name,email) - 1,john,john@abc.com - 2,andy,andy@abc.com - 3,kyle,kyle@abc.com - 4,allen,allen@abc.com sig(id,name)
I have two tables people name id man1 456 man2 123 man3 789 notes
I have two tables people name id man1 456 man2 123 man3 789 notes
Suppose you have these tables: Table Name: Salesman Fields: S_ID(Primary Key), Name Table Name:
I have 5 tables: customers id - name p_orders id - id_customer - code

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.