1

I have table, table B:

id   p.id    s.id
1      5       1
2      5       1 
3      5       2
4      5       2
5      5       3

The result looks like this:

s.id   count
1       2
2       2
3       1

I have tried:

Select count(s.id) from B group by s.id 

But its not giving me the required result. I am using MySQL.

1 Answer 1

4

It's simple:

SELECT s.id
     , count(*) as COUNT
FROM B
GROUP BY s.id;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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