Counting GROUP BY results
This post was published 11 years ago so it may be outdated.
When counting results from a SQL query that uses GROUP BY clause, you should take into account that it will count items of each group rather than groups themselves, even if you count fields that appear in the GROUP BY clause:
[sql]SELECT COUNT( country ) FROM users GROUP BY country[/sql]
Will return a row for each different country containing the amount of users from that country.
[sql]SELECT COUNT( COUNT ( country ) ) FROM users GROUP BY country[/sql]
Will return a single row with the amount of different countries in the table.
No replies on “Counting GROUP BY results”