I have a table that contains a string in a row. What I want is to have the query return the number of rows that contain the same string in descending order. So like if I had a table like:
|1 | Blue |
|2 | Red |
|3 | Red |
|4 | Blue |
|5 | Blue |
|6 | Gold |
|7 | Blue |
|8 | Gold |
I want to echo:
There are 5 Blue
There are 3 Red
There are 2 Gold
Right now This is what my query looks like:
SELECT COUNT(id), color FROM table WHERE id = ‘”.$_GET[‘id’].”‘ GROUP BY color
But this almost works for me. It outputs something like
There are 3 Red
There are 5 Blue
There are 2 Gold
But it only returns a maximum of 7 rows and they are not in order by COUNT(id)
I’ve tried ORDER BY COUNT(id) DESC but mysql says invalid grouping method and also LIMIT 10 to try to coax more results from the query but to no avail.