MySQL prompt: In aggregated query without GROUP BY, expression #1 of SELECT list contains ......

tags: 【Technology category】

Preface

Operating todaymysqlWhen querying data in the database, a prompt is encountered, the query fails, and the prompt message is as follows:

In aggregated query without GROUP BY, expression #2 of SELECT list contains nonaggregated column 'myemployees.employees.department_id'; this is incompatible with sql_mode=only_full_group_by

When running this SQL statement, there is no problem:

select MIN(salary)
from employees
where department_id=(
	select department_id
	from employees
	group by department_id
	order by MAX(salary) asc
	limit 1
);

But added a field abovedepartment_id, When running this, the above error message appears:

select MIN(salary),department_id
from employees
where department_id=(
	select department_id
	from employees
	group by department_id
	order by MAX(salary) asc
	limit 1
);

After understanding, inMySQL5.7.5, It’s turned on by defaultONLY_FULL_GROUP_BY, Which led to some of the previousSQLCan’t execute normally, in fact, it’s oursSQLCaused by irregularities becausegroup byAfter that, some of the returned data is uncertain, so this error occurs.

To sum up a sentence:that's becausesql_modeCaused by improper settings.

Resolution process

Here is the solution:

I usedNavicatConnected inNavicatEnter the following statement:

select version(), @@sql_mode;  //This step is to check

After that, enter the following command:

SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));  //Modify sql_mode


Just got an error when running againSQLCommand, this time it can run normally.

Expansion:

MySQL modify sql_mode

Intelligent Recommendation

MySQL:ERROR 1140 (42000): In aggregated query without GROUP BY, expression #1 of SELECT list c

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...

Mysql error 1140 - in aggregated query without group by, express number # 1 of success list contains nonaGgreg

Execute SQL query statement: Wrong [Err] 1140 - In aggregated query without GROUP BY, expression #1 of SELECT list contains nonaggregated column 'cust_cx.c.card_type_name'; this is incompatible with s...

Mysql join table query group error report Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggre problem

It’s the first time I’m writing a blog, and I’ll record it. I’m a vegetable dog. For linked list queries, I’m reporting a grouping error. Baidu has been working on it for...

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

Expression # 1 of SELECT list is not in GROUP BY clause and contains nonaggre… a lot behind That's what went wrong We can see many explanations online MySQL 5.7.5 and above functions depend on ...

mysql query report [Err] 1055-Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregat

1. The error message is as follows: 2. Reasons: MySQL 5.7.29 and up implement the detection of functional dependency. If only_full_group_by SQL mode is enabled (it is by default), MySQL will reject qu...

More Recommendation

Mysql encountered Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggre

The error is as follows: Expression #2 of SELECT list is not in GROUP BY clause and contains  nonaggregated column ‘sss.month_id’ which is not functionally  dependent on columns ...

Mysql error Expression #1 of SELECT list is not in GROUP BY clause and contains non

The project is running well. After changing the database server, I reported this error. version reason Recording solution If the permissions are not enough Give users permission Or use the tool to cha...

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

- Throw an exception - solution Execute SQL against sql_mode=only_full_group_by, remove ONLY_FULL_GROUP_BY...

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

the reason:   Solution: 1: View mysql configuration file location 2: Open the configuration file 3: Modify Configuration: If you do not configure this item, you can add a 4: Restart mysql   ...

[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...

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

Top