city country continent
Seoul Korea Asia
Pusan Korea Asia
Berlin Germany Europe
Hamburg Germany Europe
Peking China Asia
Shanghai China Asia
Marseille France Europe
Paris France Europe
Vatican Italy Europe
Rome Italy Europe
Venice Italy Europe
Madrid Spain Europe
Cairo Egypt Africa
Tokyo Japan Asia
Nagoya Japan AsiaI have myTable like the above
SELECT country FROM myTable GROUP BY country
The code above produces the result below.
China
Egypt
France
Germany
Italy
Japan
Korea
Spain The result has 9countries.
I like to get the number of the countries,i.e, 8.
SELECT count(*) FROM myTabley
The code above produces β15β. but I want β8β.
The code below is some of my trials for getting β8β, but all failed in getting β8β.
[code]SELECT count(*) FROM myTable group by country
SELECT count(disctinct country) FROM myTable[/code]
How can I get the number of counties β8β with myTable above?
Thank you, megazoid, but the code below which is applying your code produces SQL error
$query="SELECT COUNT(*) as countries_count
FROM (SELECT country FROM temp GROUP BY country)";
$sql=mysql_query($query); $row=mysql_fetch_assoc($sql); $countries_count= $row['countries_count'];
The error message is in the below.
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in ...