Reputation:
I have a history table that stores all actions done by users on deferments posts
id | post_id | action | user_id
1 | 5 | 1 | 3
2 | 6 | 4 | 1
3 | 6 | 4 | 4
4 | 7 | 2 | 6
5 | 7 | 3 | 2
6 | 5 | 2 | 3
7 | 4 | 5 | 3
What I want is to get all actions done by the last three users
Upvotes: 1
Views: 74
Reputation: 263723
Assuming ID
is an AUTO_INCREMENT
column,
SELECT a.user_ID, a.action
FROM tableName a
INNER JOIN
(
SELECT DISTINCT user_ID
FROM tableName
ORDER BY ID DESC
LIMIT 3
) b ON user_ID = b.user_ID
Upvotes: 2