$query = "SELECT referenced.id, referenced.name, building.type, COUNT(building.type) FROM building, referenced WHERE referenced.id = building.type GROUP BY building.type";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
echo "There are ". $row['COUNT(building.type)'] ." ". $row['name'] ."";
echo "<br />";
}
Result looks like:
There are 3 skyscrapers
There are 17 bungalows
There are 2 libraries
etc
What I would like to do is print out the results so that they display in order of greatest number. So bungalows would come top, then skyscrapers, then libraries.
Any advice on how to adapt my query would be much appreciated. I'm not sure how to use the ORDER BY in conjuntion with COUNT().
Thank you.