MySQL Query order by numer of rows?
Posted
by Clemens
on Stack Overflow
See other posts from Stack Overflow
or by Clemens
Published on 2010-03-15T19:38:00Z
Indexed on
2010/03/15
19:39 UTC
Read the original article
Hit count: 289
hi,
i have a mysql table for votes. there's am id, a project_id and a vote field (which is 1 if a specific project is voted). now i want to generate a ranking from those entries. is there a way to get the number of votes for each project_id and automatically sort the entries by the number of TRUE votes of a project with a single mysql query? Or do you know a php way?
e.g.
ID - Project ID - Vote
1 - 2 - 1
2 - 2 - 1
3 - 1 - 1
==>
Project Nr. 2 has 2 Votes
Project Nr. 1 has 1 Vote
Thanks in advance!
© Stack Overflow or respective owner