Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Subquery and counting

Status
Not open for further replies.

jamiecottonuk

Technical User
Oct 29, 2007
12
GB
HI all,

I have a table called people in my database.

it looks like this


Code:
+----+------+
| id | name |
+----+------+
|  2 | bob  |
|  1 | Jill |
|  3 | Jill |
|  4 | John |
|  5 | Jill |
+----+------+
I want to display the distinct name and how many times they are in the table
So like this

Jill - 3
bob - 1
John - 1

How would I go about doing this. I thought maybe something like this but not to sure

Code:
SELECT COUNT(name) 
FROM people 
WHERE name = 
(SELECT DISTINCT name 
FROM people);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top