[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 582
  • Last Modified:

MySQL: Group By / count question

Hi All,

Table Name:  table1
Fields:  id, firstname, surname

How can I count the number of times each surname appears?

something like...

SELECT surname, count(surname) As "count" FROM table1 GROUP BY surname

example results would be

Surname      count(surname)
Smith             10
Jones              7
Archer            2


Many thanks
0
detox1978
Asked:
detox1978
1 Solution
 
GaryCommented:
You basically have it - no speech marks

SELECT surname, count(surname) AS surname_total FROM table1 GROUP BY surname
0
 
detox1978Author Commented:
thanks.  didnt think i was too far away  :-)
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now