MySQL Forums
Forum List  »  Newbie

Re: Specify order before group?
Posted by: Callum Macdonald
Date: June 27, 2005 12:49PM

Hi Jay,

Thanks for your response.

I don't actually want the COUNT(*), but I think you're right about using MAX(Time), so I think my query would be:

SELECT UserID, MAX(Time) as 'LatestAction'
FROM TrackingActions
GROUP BY UserID
ORDER BY 'LatestAction' DESC;

The MAX() option works because it selects the MAX within the Group, which is exactly what I was after, I just couldn't figure how to get it working.

Thanks again,


chmac.

Jay Pipes wrote:
> When using GROUP BY, you need to group on
> something. Doing SELECT * means you want all the
> columns in the table, then grouped by UserID?
> That doesn't make sense.
>
> I think what you're looking for is something
> like:
>
> SELECT UserID, MAX(Time) as 'LatestAction',
> COUNT(*) as 'NumActions'
> FROM UserAction
> GROUP BY UserID
> ORDER BY 'LatestAction';
>
> Is that more like it?
>

Options: ReplyQuote


Subject
Written By
Posted
Re: Specify order before group?
June 27, 2005 12:49PM
ben
November 13, 2005 09:07PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.