Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've the following tables:

   fss_comment(idComment, post_id, text)

Is possible to write a query that give me as result a row for each post_id with total comment count for this post?


    post_id       comment_count
    101010        5
    101011        0

And so on... Thanks.

share|improve this question

closed as off-topic by bluefeet, RolandoMySQLDBA, Mark Storey-Smith, Michael - sqlbot, Max Vernon Oct 15 '13 at 16:57

If this question can be reworded to fit the rules in the help center, please edit the question.

up vote 2 down vote accepted

I think what you need would be something like the below:

select p.post_id, count(idComment)
from fss_post p left join fss_comment c on p.post_id = c.post_id
group by p.post_id
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.