As in this question: Retrieving the last record in each group, I want to query the latest entries of each group.
In difference to the linked question, I also want to add a criteria for the maximum time.
I have tried the following:
SELECT m1.*
FROM messages m1
LEFT JOIN messages m2
ON (
m1.name = m2.name AND
m1.id < m2.id AND
m2.time <= nnnnnnn
)
WHERE m2.id IS NULL
AND m1.time <= nnnnnnn;
I am not sure if this is 100% correct, Is there a better solution? Maybe without the duplicate time <= nnnnnnn
condition?