The following statement works in my database:
select column_a, count(*) from my_schema.my_table group by 1;
but this one doesn't:
select column_a, count(*) from my_schema.my_table;
I get the error:
ERROR: column "my_table.column_a" must appear in the GROUP BY clause or be used in an aggregate function
Helpful note: This thread: What does SQL clause "GROUP BY 1" mean? discusses the meaning of "group by 1
".
Update:
The reason why I am confused is because I have often seen count(*)
as follows:
select count(*) from my_schema.my_table
where there is no group by
statement. Is COUNT
always required to be followed by group by
? Is the group by
statement implicit in this case?