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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:37:27+00:00 2026-06-13T02:37:27+00:00

This is my first time asking a question on here. It has been very

  • 0

This is my first time asking a question on here. It has been very helpful with learning.

I am trying to select a table and getting only rows that have a maximum value for its particular group in another table. One of the best answers that is very close but not quite there is this one (SQL Select only rows with Max Value on a Column) but it only relates to a single table. I have found some others with multiple table but not sure how exactly to use it.

I have a table with (simplified)

prodID, quantity, mach, etc

I then have a table with

prodStatusID, prodID, userID, subStatusID

a last table with sub status names

subStatusID, subStatusName

I am trying to get a table with all of the first table and the second table but only with the row that has the maximum status number and include the right status name.
My other concern which may not matter now but in a year or two when this thing starts to really fill up is performance. I dont know bad it is to have select inside a select but if I am trying to return all productions then it will be doing a query for every production.

Just to be clearer. in the second table prodStatus there might be 2 rows with prodID of 4 but the subStatusID for the first one would be 1 and the second one would be 2. The userID will be different. All I want to get back is the second row because it has the highest status number and I need the userID and statusName associated with that row.

I have been googling for 2 days to get this answer and I saw 1 about auctions but I just dont fully understand it even after researching it.

  • 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-13T02:37:28+00:00Added an answer on June 13, 2026 at 2:37 am

    You need to create a subquery which get the maximum value of subStatusID for each prodID.

    SELECT  a.*,     -- select only columns that you want to show
            c.*,     -- asterisks means all columns
            d.*
    FROM    table1 a
            INNER JOIN
            (
                SELECT prodID, max(subStatusID) maxID
                FROM table2
                GROUP BY prodID
            ) b ON a.prodID = b.prodID 
            INNER JOIN  table2 c
                ON b.prodID = c.prodID AND
                    b.maxID = c.subStatusID
            INNER JOIN table3 d
                ON c.subStatusID = d.subStatusID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is my first time asking a question here. I tried to be well
Hi this is the first time I am asking a question here. I have
this is my first time asking a question here so apologies if I am
This is the first time i'm asking a question here at stack overflow so
this is my first time asking a question here so I hope I am
this is my first time asking for some help here although I've been lurking
this is my first time asking a question so bear with me. I am
this is my first time asking a question on stackoverflow. I'm working on a
First time asking a question here. Usually I can find my answer without having
This is my first time asking a question, please be gentle! I have a

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.