Tag Archives: SELECT list is not in GROUP BY clause and contains nonaggregated

[Solved] SELECT list is not in GROUP BY clause and contains nonaggregated

[questions]

[reason]

MySQL 5.7.5 and above functions depend on the detection function. If the ONLY_FULL_GROUP_BY SQL mode is enabled (by default), MySQL will reject select lists, HAVING conditions, or ORDER BY list queries that reference non-aggregate columns that are neither named in the GROUP BY clause, nor are they functionally dependent on them. (Before 5.7.5, MySQL did not detect the functional dependency, ONLY_FULL_GROUP_BY is not enabled by default. For instructions on the behavior before 5.7.5, please refer to the “MySQL 5.6 Reference Manual”.) The following solution is not the final solution, The error is only blocked, but the problem still exists.

The result of looking for a long time is the mysql5.7 database reason! !

[solution]

Open navcat and query with SQL:

First:

select @@global.sql_mode;

Query whether  ONLY_FULL_GROUP_BY exists. If it exists, reset the value (in fact, delete ONLY_FULL_GROUP_BY).

set @@global.sql_mode ='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';

Then there’s no problem.

SELECT list is not in GROUP BY clause and contains nonaggregated

1. Error

> 1055 - Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'n.wifi_mac' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

2. Inquiry

SELECT @@sql_mode;
Outcome:
ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION

3. Modify the/etc/my.cnf file and add SQL_ Model (delete only_full_group_by)

SELECT @@sql_mode;
Outcome:
ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION