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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:28:02+00:00 2026-05-20T17:28:02+00:00

I have 2 tables, one that holds records with some data related to it

  • 0

I have 2 tables, one that holds records with some data related to it and another that holds historic data for first table.

The historic table may have many rows for each row of the main table, what i want to do is join on the newest record from the historic table when pulling out one or more from the main table.

I’ve tried joining a subquery using a group by id, that didn’t work, I cant use a limit because I want to select more than one record.

  • 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-20T17:28:03+00:00Added an answer on May 20, 2026 at 5:28 pm

    Assuming that historical table has PK composed of original id and timestamp

    SELECT table.*, ht1.*
    FROM table INNER JOIN historical_table ht1
         ON table.id = ht1.id
         LEFT JOIN historical table ht2
         ON ht1.id = ht2.id AND ht1.timestamp < ht2.timestamp
    WHERE ht2.timestamp IS NULL
    

    Main part of the logic is select rows for which there are no newer records (ht2.timestamp is null)

    This is a common max-per-group so question (and there are other ways to go about it)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was making one table that have two foreign key to another tables. But
Given that I have a table that holds vehicle information and one of those
I want to delete multiple records at once. I have two tables, one that
I have a database table that holds information for received files. One of the
I have one table which holds lots of records. Its for an auction site.
I have a database with a table that records data coming from various sources.
I have two tables, one that has 450 rows, the other is a Sort
I have two tables, one that has a foreign key from the other. I
I have 2 tables that their rows have one on one relation.. For you
I have two tables that link together through an id one is submit_moderate and

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.