mysql - Get all actions of the last three users -
i have history table stores actions done 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 want actions done lastly 3 users
assuming id
auto_increment
column,
select a.user_id, a.action tablename inner bring together ( select distinct user_id tablename order id desc limit 3 ) b on user_id = b.user_id
sqlfiddle demo mysql sql
No comments:
Post a Comment