Mario Mario - 3 months ago 8
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

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

select  count(distinct country)
from    YourTable