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.
Assuming that historical table has PK composed of original id and timestamp
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)