Mondeo Posted December 8, 2006 Posted December 8, 2006 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 Quote
dinoboy Posted December 9, 2006 Posted December 9, 2006 Yes, this can be done with COUNT() function and GROUP BY statement 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.