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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.