Alex Chapp Alex Chapp -4 years ago 186
MySQL Question

mySQL count only returning one result unless using group by

using the SQL query

select,count( as 'followers'
from user u,follow f
where u.type = 'c' AND f.followee =
group by

gets me the correct value for all users in my database, however, the exact same query without the group by line only gives me the first value. I am learning SQL for the first time and was having a hard time figuring out why this is.

Answer Source

When you use count without group by it will count all the records and returns single line while when you use count with group by it will group the users on the base of their names and returns the count of each group.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download