MySQL ORDER BY COUNT()?

For what it's worth, any use of an aggregate function in the select-list means that the result set will have only one row. It makes little sense to sort a results set with a single row.

If you meant to get a count of ratings per distinct value of prof, you should use this:

$order_list = mysql_query("
    SELECT prof, COUNT(*) AS PROFCOUNT, 
    FROM prof_rating 
    GROUP BY prof
    ORDER BY PROFCOUNT ASC'");

That will output multiple rows, one row per prof value, with the count of rows for each given prof value.


Alias the column name and then put that in your order by clause :)

$order_list = mysql_query("
SELECT COUNT(prof) AS PROFCOUNT, 
FROM prof_rating 
ORDER BY PROFCOUNT ASC'");