I have a routine that runs every few hours that creates several entries in a table used for logging. What I need to do is select all the records with the most recent timestamp that have a common account id. Something like this:
SELECT *
FROM TABLE_logs
WHERE ACCOUNT_ID='12345'
ORDER BY TIMESTAMP DESC
Where I'm stuck is that I can't say LIMIT 5
or something like that because the number of records created at each routine interval could be different. So, for example, when the routine runs at 10AM, it may create 6 table entries and only 4 table entries at 2PM.
Is there a way to select the grouping of the latest records without knowing how many there are?