Search code examples
mysqlsqlmysql-error-1111

mysql nested count - how?


Here's the initial query:
SELECT COUNT(column) FROM table GROUP BY column;
This gives me something like the following:
COUNT(column)
2
4
1
1
3
etc.
BUT I need to to count all of those together in one number! How could I do that? COUNT(COUNT(column)) throws an error: "Invalid use of group function".
P.S. this is not used in any program, if it was, it would be trivial to count them together.


Solution

  • remove the group by:

    select count(column) from table;
    

    if you need distinct columns:

    select count(distinct column) from table; -- might not work in mysql
    

    or:

    select count(*) from (select distinct column from table) as columns;