Christopher
Christopher

Reputation: 13

Ordering a group by in sql

Hi I am sorry if this has been asked somewhere else but I cant seem to find any answers for this.. or non that I can get to work. I have a table with a list of actions for each user. I am trying to get every users last action. I am wanting to group by user and order by the time. what this seems to be doing is returning the first action and ordering that.

Here is the query I am using:

SELECT 
     userid, 
     time
FROM
     useractions
GROUP BY 
     userid
ORDER BY 
     time

Any help would be much apreciated. Sorry if this turns out to be a stupid question. Thanks

Upvotes: 0

Views: 87

Answers (1)

Miller
Miller

Reputation: 1156

Try this

SELECT 
     userid, 
     max(time)
FROM
     useractions
GROUP BY 
     userid

Upvotes: 4

Related Questions