Can I do this with SQL

Mondeo

Well-known member
Joined
Nov 10, 2006
Messages
128
Location
Sunny Lancashire
I have an SQL table with a column called Town, it looks something like this

Burnley
Burnley
Burnley
Blackburn
Preston
Colne
Colne
Preston
Blackburn

I need to get the counts of each town in the database so I want my results to look like this

Burnley 3
Blackburn 2
Preston 2
Colne 2

Is there anyway I can do it just using a plain SQL statement?

Thanks
 
Yes, this can be done with COUNT() function and GROUP BY statement

Code:
SELECT COUNT(name) AS count, name FROM table GROUP BY name

Where table is name of the table and column name is the name of the column you use.
 
Back
Top