Resolve packet error reporting Expression 1 of SELECT list is not in GROUP BY clause and contains nonaggregated larger than version 5.7 mysql

  • 2021-12-13 10:01:24
  • OfStack

Reason:

MySQL 5.7. 5 and up implement the detection of functional dependencies. If the only_full_group_by SQL mode is enabled (by default), MySQL rejects queries that select list, conditional, or sequential list references, which refer to unnamed, non-aggregated columns in the group rather than depend on them functionally. (Prior to 5.7. 5, MySQL did not detect functional dependencies, and only_full_group_by was not enabled by default. Refer to the MySQL 5.6 Reference Manual for a description of the previous 5.7. 5 behavior. )

You can view the contents of sql_mode by executing the following command:


mysql> SHOW SESSION VARIABLES;
mysql> SHOW GLOBAL VARIABLES;
mysql> select @@sql_mode;

It can be seen that the values of sql_mode for session and global are:


ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

only_full_group_by Description:

only_full_group_by: To use this is to use the group rule like oracle1. The columns of select must be in group, or they must be aggregated columns (SUM, AVG, MAX, MIN). In fact, this configuration is similar to distinct at present, so it is good to remove it

Resolve:


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';<br data-filtered="filtered">set session sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';<br data-filtered="filtered">

Summarize


Related articles: