SELECT S.country, COUNT( DISTINCT S.minid ) AS theCount FROM ( SELECT country, name, MIN(id) AS minid FROM names GROUP BY country, name ) AS S GROUP BY S.country ORDER BY S.country