I have 3 tables user, person and company.
the user_id is a foreign key in both person and company tables.
what I want to do is to count how many persons and companies are related to each user, so I did the following query:
select u.id , u.username, count(c.user_id) as count_company, count(p.user_id) as count_people
from user u left join company c on (u.id = c.user_id)
left join person p on (u.id = p.user_id)
group by u.id, u.username
but I'm getting wrong result!!
This is the result I get:

however, when I try to count only the companies related to each user using this query:
select u.id , u.username, count(c.staff_user_id) as count_company
from fos_user u left join company c on (u.id = c.staff_user_id)
group by u.id, u.username
