Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregate

1. Reason

Such an error in aggregate query is because the mode set by mysql contains ONLY_FULL_GROUP_BY

mysql> select @@sql_mode;
+-------------------------------------------------------------------------------------------------------------------------------------------+
| @@sql_mode                                                                                                                                |
+-------------------------------------------------------------------------------------------------------------------------------------------+
| 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 |
+-------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

Two, modify

Modify in the configuration file

 

sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
mysql> select @@sql_mode;
+------------------------------------------------------------------------------------------------------------------------+
| @@sql_mode                                                                                                             |
+------------------------------------------------------------------------------------------------------------------------+
| STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |
+------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

Then restart the service

 

Three, cause analysis

According to the examples on the Internet, I reproduced it myself. Reference materials:、

 

I created a table in the database, game, with the following data

 

When I execute the following sql statement, an error occurs

sql statement: select name, group_id from game group by group_id;

error:

1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 't.game.name' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

 

If ONLY_FULL_GROUP_BY is removed, no error will be reported

 

The meaning of the sql statement is to sort by group, but there are two records in group B here, and I don't know which one to return, so an error is reported.

In fact, there will be no problem with mysql. Such an error can only mean that there is a problem with the sql statement we wrote.

Four, appendix

 

STRICT_TRANS_TABLES:
 In this mode, if a value cannot be inserted into a transaction table, the current operation is interrupted, and no restrictions are imposed on non-transactional tables
NO_ZERO_IN_DATE:
   In strict mode, dates with a month or day part of 0 are not accepted. If the IGNORE option is used, we insert '0000-00-00' for similar dates. In non-strict mode, the date can be accepted, but a warning will be generated.
NO_ZERO_DATE:
 In strict mode, do not use '0000-00-00' as a legal date. You can still insert zero dates with the IGNORE option. In non-strict mode, the date can be accepted, but a warning will be generated
ERROR_FOR_DIVISION_BY_ZERO:
 In strict mode, during INSERT or UPDATE, if it is divided by zero (or MOD(X, 0)), an error is generated (otherwise it is a warning). If this mode is not given, MySQL returns NULL when dividing by zero. If you use INSERT IGNORE or UPDATE IGNORE, MySQL generates a division by zero warning, but the result of the operation is NULL
NO_AUTO_CREATE_USER:
 Prevent GRANT from automatically creating new users unless a password is also specified.
NO_ENGINE_SUBSTITUTION:
 If the required storage engine is disabled or not compiled, an error is thrown. When this value is not set, replace with the default storage engine and throw an exception

Intelligent Recommendation

Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 't.fix_code

Given as follows Cause of the problem: MySQL 5.7.5 and above detection function is dependent Open navcat, With sql query: select @@ global.sql_mode   Check out the value of: ONLY_FULL_GROUP_BY,ST...

Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'a.log_id'

Caused by: java.sql.SQLSyntaxErrorException: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘a.log_id’ which is not functionally dependent on colu...

Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column

After installing mysql5.7.19, as long as the execution statement contains group by, it will report this error There are roughly two solutions for Baidu on the Internet, but it does not solve this prob...

[MySQL] Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column

Encounter problems Recently, a new function has been developed for a public account of a company's system. One of the functional points involved is to query the latest record of each strong electric w...

mysql error: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggre

Error:Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggre 1. Description: The tables grades in the database are SQL statement: return: Expression #1 of SELECT list is not in G...

More Recommendation

idea error Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggre

Idea report error Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggre How to solve When writing a query statement to execute, the idea log reports an error Expression #1 of SE...

1055-Expression #1 of SELECT list is not in GROUP BY clause and contains

During the development process today, because the previous project has been developed and the database migration has been completed, during the operation today, an error occurred when summing up by gr...

Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘qyzyt.TC_C

Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘qyzyt.TC_COMPANY_INFO.DEVID’ which is not functionally dependent on columns in GROUP BY clause; th...

Observed EXPRESSION # 1 of SELECT LIST IS NOT IN GROUP BY CLAUSE AND CONTAINS NONAGGRE

Used in group by, but reported the following error: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘sss.month_id’ which is not functionally depend...

Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘bdas_hz.a.

Computer: M1 chip MacBook Air Background: When executing the rejection operation after project deployment (the project is OA and involves forms), the database reports an error: Expression #1 of SELECT...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top