Forum Moderators: coopster
Right now I'm using SELECT DISTINCT to get the unique matches, only to query the database again to see how many of each there are.
There are about 1800 rows (and growing day by day)... About 15 unique (not growing too much)...
Ok, the column is a list of countries. I only want to get unique countries (if USA is listed more than once, it should still only be displayed once)... which is why I'm using DISTINCT. But, I still want to know how many times each country appears.
The output is something like this:
Andorra (2)
Belgium (14)
Canada (53)
Denmark (28)
...
SELECT DISTINCT country FROM table ORDER BY country ASC
The problem isn't how to get a list of all unique countries. The problem is how to figure out how many of each, without having to perform extra queries.
$result = mysql_query("SELECT DISTINCT country FROM table ORDER BY country ASC");
while($get = mysql_fetch_row($result)) {
mysql_query("SELECT * FROM $mysql_profile_table WHERE country='".$get[0]."'");
$find = mysql_num_rows($lookup);
echo $get[0]." (".$find.")<br>";
}
See? I don't want to do it that way... I want to know if there's an easier way of doing it, preferably in one query.