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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:56:31+00:00 2026-06-06T01:56:31+00:00

The question I have is kind of simular to this one – MySQL select

  • 0

The question I have is kind of simular to this one – MySQL select 1 row from inner join

However, it was never really answered in the way that I needed it. So I thought I would ask.

I have a table A (tableA) and this table has a load of states in tableB. New states keep being added all the time.

TableB has a column ‘State’ which has a foreign key to TableA.Id. This table B has a value and timestamp

I am trying to get ONE query which will bring back ALL values in TableA, with an inner join to bring the LATEST ‘value’ of those rows from tableB. The latest being the one with the latest time.

I know how to do an inner join where it needs to be, and I know how to order a table to bring back the latest ‘time’ row, however I dont know how to put these two together and create a single query.

I’m sure I will have to have a Select within a select, which is fine. However, what I am trying to avoid is to bring a DataTable back with all my results from TableA and do a query for each of those on tableB seperately.

Any ideas?

EDIT – I have made a mistake with the question, I only really noticed when trying to implement one of the answers.

I have a foreign key between TableA.id and TableB.proId

TableA – ‘Id’, ‘Name’
TableB – ‘Id’, ‘proId’, ‘State’, ‘time’

I want to bring back all values of TableA with a join on B, to bring back the ‘State’ of the Max time

  • 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-06T01:56:32+00:00Added an answer on June 6, 2026 at 1:56 am
    SELECT T.Id,
           T.Name,
           T.State
      FROM 
    (
        SELECT A.ID,
               A.Name,
               B.State,
               ROW_NUMBER() OVER ( PARTITION BY A.ID ORDER BY B.Timestamp DESC) RowNumber
          FROM Table_A A
         INNER JOIN Table_B B on A.Id = B.ProdId
    ) T
    WHERE T.RowNumber = 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this kind of question. In my form, i got this as a
Kind of like this question I have many text snippets that I use many,
This question is kind of related to another question but I have a specific
I guess this is kind of an odd question but I have tried setting
Kind of a follow up to a question from yesterday. I have a hash
I know this is kind of a dumb question, but does anyone have an
I have a very similar problem to the one described in this question .
This is kind of similar to this question: PHP MySQL INSERT fails due to
I have a question about reflection I am trying to have some kind of
A question about boost::shared_ptr here: I have 3 Classes. A is some kind of

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.