tags: sql_mode=only_full_group_by
There is no problem running on MySQL 5.5.27. The error of sql_mode=only_full_group_by is reported on MySQL 5.7.24:
Error 1140: In aggregated query without GROUP BY, expression #1 of SELECT list contains nonaggregated column 'sx.u.id';
this is incompatible with sql_mode=only_full_group_by
When SELECTing a column that does not belong to the GROUP BY column, the column in the group may have multiple values, but there is only one value space in the result. Therefore, it is often necessary to tell the database how to combine these multiple values into one value. Usually, this is the same as the aggregate function COUNT(), SUM(), MAX(), etc... I say in general, because most other popular database systems stick to this. However, in MySQL prior to version 5.7, the default behavior was more tolerant because it wouldn't complain and then choose any value at will! It also has an ANY_VALUE() function if you really need the same behavior as before and can be used as another solution to this problem. This flexibility comes at a price because it is non-deterministic, so I won't recommend it unless you have a good reason to need it. MySQL now has only a full reason for opening the default_full_group_by setting, so it's best to get used to it and make your query conform to it.
There are two solutions
1. Method 1
Standardize SQL, eliminating the possibility of any ambiguity
E.g:
SELECT name, age, SUM(points) FROM scores GROUP BY name //correct
SELECT name, age, SUM(points) FROM scores //Error (after 5.7)
2. Method 2 (no need to make any changes in the current query)
1). Open the configuration file
sudo vim /etc/mysql/my.cnf
2). Copy the following to my.cnf
[mysqld]
sql_mode =
STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
3). Exit save
:wq!
4). Restart MySQL
sudo service mysql restart
Group by using a query in Mysql when the following error occurs: In the error was found, it has a problem sql_mode = only_full_group_by. Found by looking for the pattern must have a column correspondi...
This wrong Chinese translation: In the aggregate query without using the Group By clause, the first expression in the SELECT list contains non-polymeric column 'school.student.s_id'; this is not possi...
The specific errors are as follows: the reason: MySQL 5.7.5 and above functions depend on the detection function. If ONLY_FULL_GROUP_BY SQL mode is enabled (by default), MySQL will reject select lists...
my situation : Mysql 5.7.21 version runs sql and reports the same error. The same sql runs directly locally without error. However, this error occurs when connecting to Mysql on the server (even runni...
MySql reports an error sql_mode=only_full_group_by Prospect introduction problem solve Prospect introduction There is a long long ago project. As the purchased Alibaba Cloud database expired and no on...
1 Reason: Use group_concat in SQL to combine, if you are other group by reason, please find other solutions Online explanation: After mysql5.7.5, the default opened online, so some SQL could not be ex...
Problem: mysql5.7, error when executing sql statement: In aggregated query without GROUP BY, expression #2 of SELECT list contains nonaggregated column'department_id'; this is incompatible with sql_mo...
1. Reason of error After MySQL 5.7.5, only_full_group_by becomes one of the default options of sql_mode, which may cause some SQL statements to fail. For example, when group by is used for group query...
1. Query mysql's mode: We need to remove the only_full_group_by mode 2. Set the mode Windows Open the my.ini file in the MySQL installation directory Add configuration Save after modification 3. Resta...
When running the above SQL query, the error message is displayed: In aggregated query without GROUP BY, expression #1 of SELECT list contains nonaggregated column 'school.student.s_id'; this is incomp...