0

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)

1
  • This is because count is usually applied to all records. GROUP BY as suggested below should do the trick. Commented Aug 24, 2011 at 22:28

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.