Small MySQL Q

Soldato
Joined
4 Jul 2004
Posts
2,647
Location
aberdeen
Hi,
I have a DB with many of the same word in a field, and to list them all (all the words, not every single entry of the words) i am using
$query = "select DISTINCT towncity from table";

However i want to list it by the ones that are most popular - ie list the towncity with the most rows that have that towncity first. If that makes sense?
If anyone could help that would be great. Order by doesn't seem to work...
Thanks:D
 
PHP:
$query =  "SELECT COUNT(towncity), towncity FROM table GROUP BY towncity ORDER BY COUNT(towncity) DESC";

i think that should work. :)
 
Back
Top Bottom