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
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...
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...
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… a lot behind That's what went wrong We can see many explanations online MySQL 5.7.5 and above functions depend on ...
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...
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 ...
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...
- Throw an exception - solution Execute SQL against sql_mode=only_full_group_by, remove ONLY_FULL_GROUP_BY...
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 ...
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...