I knew that normal columns followed by aggregate functions are allowed only if a Group By including them follows.
But then why is the following working?
mysql> select payee,sum(amount) from checks;
+---------+-------------+
| payee | sum(amount) |
+---------+-------------+
| Ma Bell | 893.76 |
+---------+-------------+
1 row in set (0.00 sec)
This behavior is an “extension” to MySql:
However, This behavior is actually a configurable setting in MySql:
It is best to respect the
group byand add all non-aggregated columns, especially if there’s the possibility that you might someday migrate to a server that hasONLY_FULL_GROUP_BYturned on.