I’m trying to do a query that fetches data per hour but instead of the normal group by hour I want to narrow it down and only get the latest hour – meaning the newest data within that hour. With the picture shown below what I wanted to get is the rows with red boxes. If you will notice, first red row is 10:59:51 which means it’s the only row that’s within 10:00:00 and 10:59:59. For the rest of the rows that is on 12:00 and above I wanted to get 12:37:14 because it’s the latest or newest for that hour range.

I have a simple query that groups the data by hour using HOUR() like:
SELECT userid, username, date_created
FROM user_accounts
WHERE date_created >= '2009-10-27 00:00:00' AND date_created < '2009-10-27 23:59:59'
GROUP BY HOUR(date_created)
The query, however, is just grouping it by hour 10 and 12 which returns id 24 and 25 – but what I needed is id 24 and 28. Any ideas?
Try