Felipe Pelá
Felipe Pelá

Reputation: 171

Need a hand with a simple query

I need a help with a query. I think is not so difficult.

I need to do a select with distinct and at the same time, do a count(*) of how many rows are returned by this distinct.

One example:

Table names>
Id   Name
1    john
2    john
3    mary

I need a query thats return:

Name    Total
john    2
mary    1

Upvotes: 0

Views: 89

Answers (3)

BruceHill
BruceHill

Reputation: 7164

SELECT name, count(*) as occurrences FROM names GROUP BY name

Upvotes: 0

jfollas
jfollas

Reputation: 1235

SELECT name, COUNT(*) FROM names GROUP BY name

Upvotes: 2

Paul Tomblin
Paul Tomblin

Reputation: 182782

select name, count(*) from names group by name;

Upvotes: 5

Related Questions