Solved

Sort by COUNT() - MYSQL

Posted on 2009-07-14
4
403 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
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…

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now