Take the 2-minute tour ×
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. It's 100% free, no registration required.

I've the following tables:

   fss_post(post_id,text)
   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?

EXAMPLE:

    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.

add comment

1 Answer 1

up vote 1 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
add comment

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