I have a table with actions performed by actors and want to return 10 of the most recent actions. I want actors to be unique within this list. ‘created’ is a time/date stamp. How can I do this most efficiently? I came up with the following query, which works:
SELECT *
FROM activities a
JOIN
(SELECT actor, MAX(created) created
FROM activities
WHERE comment_type <> 'profile.status'
GROUP BY actor) t ON (a.actor = t.actor AND a.created = t.created) LIMIT 10
The table could eventually be quite large.
You could put the limit 10 inside the subquery.
Other than that it looks OK