List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:June 3 1999 7:12pm
Subject:Re: Count distinct and totals
View as plain text  
At 12:40 PM -0500 6/3/99, Darren Sweeney wrote:
>Hi
>
>I have a table which has a simple field: name
>
>This field may contain the same name many times.
>
>What i need to do is to count how many distinct names there are and how
>many times their name is listed to produce something like:
>
>name | count
>==========
>john   | 10
>Ted    | 15
>Pat    | 15
>
>etc. etc.
>
>I am struggling to be able to find the correct select formula ... i think
>i am looking too deeply as i am sure it is quite simple ...
>
>I am trying:
>
>select distinct name as name, count(distinct name) as count from tablename;
>
>Thanks for any help
>
>Darren


The MySQL tutorial in the manual has examples that show how to do what
you want.  The second, third, and fourth example in the "Counting Rows" section
are all instances of your type of query:

http://www.mysql.com/Manual_chapter/manual_Tutorial.html#Counting_rows

--
Paul DuBois, paul@stripped
Northern League Chronicles: http://www.snake.net/nl/
Thread
Count distinct and totalsDarren Sweeney3 Jun
  • Re: Count distinct and totalsSasha Pachev3 Jun
  • Re: Count distinct and totalsPaul DuBois3 Jun
Re: Count distinct and totalsDarren Sweeney3 Jun