Solved

Sort by COUNT() - MYSQL

Posted on 2009-07-14
4
425 Views
Last Modified: 2012-05-07
Hi, I have the following mysql query;

SELECT idea_id, COUNT(vote_id) FROM int_votes GROUP BY idea_id ORDER BY COUNT(vote_id) DESC

I want to sort the results by the COUNT, but when I try the above it says 'invalid use of group'.

Can anyone tell me where I'm going wrong?
0
Comment
Question by:SheppardDigital
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
Mushq earned 500 total points
ID: 24847762
0
 
LVL 14

Expert Comment

by:flob9
ID: 24847775
Your query seems fine to me
0
 

Author Closing Comment

by:SheppardDigital
ID: 31603185
I changed my query to
SELECT idea_id, COUNT(vote_id) as count FROM int_votes GROUP BY idea_id ORDER BY count DESC
0
 
LVL 14

Expert Comment

by:flob9
ID: 24847807
The first version was working on mysql 5 ... good point mushq :)
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question