开发者

MySQL & PHP: Joins & Counts

I want to select all users from my table where access_level_id!=0. I also want to count the number of entries in another table where the user id matches a field (this could be 0 or 100).

I have:

SELECT users.id, count(clients.id) as count FROM $db[users] as users 
                              LEFT JOIN $db[clients] as clients 开发者_运维知识库ON users.id=clients.salesrep_id
                              WHERE users.access_level_id!='0'

This is returning just a single number (17)


You have to group the results. Try adding GROUP BY users.id to your Query.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜