Suppose I have a table with the following contents:
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 an erroneous SQL query with a group by clause and without any aggregation in the id column and get the 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 the mysql client or perhaps some other tool check this request and give an error or warning when using group by without aggregation?
source share