Selecting the most recent row for each user

I have a table with columns user_id, time_stampand activitywhich I use to transcode user actions for the audit log.

Now I would like to get the latest timestamp for each unique one user_id. How to do it?

+3
source share
2 answers

SELECT MAX(time_stamp), user_id FROM table GROUP BY user_id;

+7
source

The following query should be what you want ...

select user_id,max(time_stamp) from yourtable group by user_id order by user_id, time_stamp desc 
+3
source

All Articles