mysql GROUP BY clause validation
error-handling, mysql, sql, validation, warnings
Solution
Yes, you can do this:
To disable the MySQL GROUP BY extension, enable the `ONLY_FULL_GROUP_BY` SQL mode.
mysql> SET sql_mode = 'ONLY_FULL_GROUP_BY';
See the documentation here. Also, this section on server modules may help.
Problem
Suppose I have a table with the following content: ``` mysql> select * from test; +----+------+ | id | val | +----+------+ | 1 | 1 | | 2 | 1 | | 3 | 1 | | 4 | 1 | | 5 | 2 | | 6 | 2 | | 7 | 2 | | 8 | 2 | +----+------+ 8 rows in set (0.00 sec) mysql> ``` Now I run erroneous SQL query with `group by` clause and without any aggregation on `id` column and get wrong results: ``` mysql> select id, val from test group by val; +----+------+ | id | val | +----+------+ | 1 | 1 | | 5 | 2 | +----+------+ 2 rows in set (0.00 sec) mysql> ``` Can mysql client or probably some other tool validate this query and issue error or warning on using `group by` without aggregation?