How many B and C has A?

Viewed 86

I have this tables:

A:
id
1
2

B:
id a_id
1  1
2  1
3  1

C:
id a_id
1  1
2  1
3  2

I need this result:

A, CountB, CountC
1,      3,      2
2,      0,      1

This try doesnt work fine:

SELECT 
    A.id, COUNT(B.id), COUNT(C.id)
FROM
    A
        LEFT JOIN
    B ON A.id = B.a_id
        LEFT JOIN
    C ON A.id = C.a_id
GROUP BY A.id

How must be the sql sentence without using correlative queries?

1 Answers
Related