Mario Mario - 1 year ago 58
SQL Question

Count how many different countries are in the table

I have a table like this:

ID country
-------------
1 US
2 Japan
3 China
4 US
5 China


How can one query the table, so that it returns how many different countries are in the table (i.e 3)?

Answer Source

The following SQL query will result in counting the number of unique countries in your table.

select  count(distinct country)
from    YourTable