MySQL Query: ORDER BY before GROUP BY ?

I have a Query which returns unique users but it doesn't order them how I want, the ORDER BY doesn't seem to even affect the results.  Here's the query:

SELECT user, words
FROM posts
WHERE date > 1325397600
GROUP BY user
ORDER BY words DESC

I want it to select unique unique users but grab the rows for those unique users with the highest words count.  A query like this would be perfect but it doesn't work:

SELECT user, words
FROM posts
WHERE date > 1325397600
ORDER BY words DESC
GROUP BY user
davideo7Asked:
Who is Participating?
 
Patrick MatthewsCommented:
It's not entirely clear what you want, but here is a try:

SELECT user, MAX(words) AS MaxWords
FROM posts
WHERE > 1325397600
GROUP BY user

Open in new window

0
 
viralypatelCommented:
use a nested query and use order by on the outer one. Should work.
0
 
davideo7Author Commented:
matthewspatrick: That actually worked!  Do you think you could help me with another query where I have a similar situation?

http://www.experts-exchange.com/Programming/Languages/SQL_Syntax/Q_27516131.html
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.