soycharliente Posted June 29, 2007 Share Posted June 29, 2007 What's the best/quickest way to count unique row entries? I have a table of data with one field being 'loc' and want to count each unique loc. So if I have: id loc 1 mexico 2 mexico 3 china 4 usa 5 usa I want to run a query and return something like: mexico 2 china 1 usa 2 Link to comment https://forums.phpfreaks.com/topic/57656-solved-counting-unique-db-table-rows/ Share on other sites More sharing options...
tippy_102 Posted June 29, 2007 Share Posted June 29, 2007 SELECT DISTICT loc, count(loc) AS loc_count FROM .... should do what you want. Link to comment https://forums.phpfreaks.com/topic/57656-solved-counting-unique-db-table-rows/#findComment-285486 Share on other sites More sharing options...
teng84 Posted June 29, 2007 Share Posted June 29, 2007 SELECT country,count(distinct `country`) FROM `table` group by country that works Link to comment https://forums.phpfreaks.com/topic/57656-solved-counting-unique-db-table-rows/#findComment-285493 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.