mysql multi count() in one query
Posted
by
atno
on Stack Overflow
See other posts from Stack Overflow
or by atno
Published on 2010-12-31T07:08:02Z
Indexed on
2010/12/31
7:54 UTC
Read the original article
Hit count: 202
Hi,
I'm trying to count several joined tables but without any luck, what I get is the same numbers for every column (tUsers,tLists,tItems)
. My query is:
select COUNT(users.*) as tUsers,
COUNT(lists.*) as tLists,
COUNT(items.*) as tItems,
companyName
from users as c
join lists as l
on c.userID = l.userID
join items as i
on c.userID = i.userID
group by companyID
The result I want to get is
---------------------------------------------
# | CompanyName | tUsers | tlists | tItems
1 | RealCoName | 5 | 2 | 15
---------------------------------------------
what modifications do i have to do to my query to get those results?
Cheers
© Stack Overflow or respective owner