Brandon 10x
Brandon 10x

Reputation: 43

SQL: Number of Comments left by single commenter

I am trying to get the number of comments left by each commenter (subscriber) and order from highest to least.

For Starters this was the first link I went to :

SQL: How to get the count of each distinct value in a column?

Similar problem, except in my first column the values may repeat. Mine looks something like this.

email   | comment
--------------------
foo@bar | blah..
bar@bar | blah..
zob@bar | blah..
foo@bar | blah..
foo@bar | blah..
bar@bar | blah..

and essentially all I need to do is get an output like this

-foo@bar (3)
-bar@bar (2)
-zob@bar (1)

I know this may be very trivial, I just don't use SQL queries that often.

Upvotes: 1

Views: 79

Answers (1)

crthompson
crthompson

Reputation: 15865

select 
  email, count(*)
from
  mytable
group by email
order by count(*) desc

Here's a fiddle

Upvotes: 4

Related Questions