How to get the last record of a group in MySQL?
SELECT id, category_id, post_title FROM posts WHERE id IN ( SELECT MAX(id) FROM posts GROUP BY category_id ); This will return the posts with the highest IDs in each group. Save this answer.
How to get latest record of each user in MySQL?
How to Select Most Recent Record for Each User. First, we get the latest date for each user id using GROUP BY. Now that we know the most recent date for each user id, we join this result with our original table to get the latest record by user group.