Hello,

Why is the COUNT aggregate function compulsory with GROUP BY?

As I understand it is not. For example
I have a table
name,salary,year

SELECT name,salary
FROM employees
GROUP BY name
ORDER BY salary

Will provide me the max salary, kind of like the equivalent of SELECT MAX, but it still works. Just a thought.

Comments

irakli’s picture

Status: Active » Closed (works as designed)

It's not in MySQL, but it is in PostgreSQL and Views, trying to be cross-DB-compliant is enforcing the constraint, so we can not avoid it, either.

It's not the end of the world though.

Given that unique name always has the same salary (the same person does not have two different salaries) you can just add "salary" to the list of group_by fields and it will give you what you need.