Solve the grouping error Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated in MySQL versions greater than 5.7

Solve the grouping error Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated in MySQL versions greater than 5.7

reason:

MySQL 5.7.5 and up implements detection of functional dependencies. If the only_full_group_by SQL mode is enabled (which it is by default), MySQL rejects queries whose select lists, conditions, or order lists refer to nonaggregate columns that are not named in the group by without being functionally dependent on them. (Prior to 5.7.5, MySQL did not detect feature dependencies and only_full_group_by was not enabled by default. See the MySQL 5.6 Reference Manual for a description of the pre-5.7.5 behavior.)

Execute the following command to view the content of sql_mode:

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: This option uses the same group rules as Oracle. The selected columns must be in the group or be aggregate columns (SUM, AVG, MAX, MIN). In fact, I personally feel that this configuration is similar to distinct, so just remove it.

solve:

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

The above is the solution to the grouping error Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated in MySQL version greater than 5.7. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

You may also be interested in:
  • MySQL group by method for single word grouping sequence and multi-field grouping
  • MySql Group By implements grouping of multiple fields
  • Mysql uses group by group sorting
  • How to use GROUP BY in MySQL to get the first N records
  • Detailed explanation of the implementation principle of MySQL group query Group By
  • MySQL grouping to get the first few records in each group (ranking) with research on group by and order by
  • Implement group by based on MySQL to get the latest data of each group

<<:  Detailed explanation of nginx forward proxy and reverse proxy

>>:  JS implements the rock-paper-scissors game

Recommend

Implementation code of jquery step progress axis plug-in

A jQuery plugin every day - step progress axis st...

How to turn local variables into global variables in JavaScript

First we need to know the self-calling of the fun...

Vue implements left and right sliding effect example code

Preface The effect problems used in personal actu...

Shorten the page rendering time to make the page run faster

How to shorten the page rendering time on the bro...

Detailed steps for Linux account file control management

In the Linux system, in addition to various accou...

Example code for implementing image adaptive container with CSS

There is often a scenario where the image needs t...

Detailed explanation of several ways to install CMake on Ubuntu

apt install CMake sudo apt install cmake This met...

Docker Compose one-click ELK deployment method implementation

Install Filebeat has completely replaced Logstash...

Detailed explanation of the use of Element el-button button component

1. Background Buttons are very commonly used, and...

Detailed usage of docker-maven-plugin

Table of contents Docker-Maven-Plugin Maven plugi...

HTML is the central foundation for the development of WEB standards

HTML-centric front-end development is almost what ...

Detailed explanation of how to use several timers in CocosCreator

1. setTimeOut Print abc after 3 seconds. Execute ...

Docker installs redis 5.0.7 and mounts external configuration and data issues

Redis is an open source NoSQL database written in...

VUE implements timeline playback component

This article example shares the specific code of ...

Nginx one domain name to access multiple projects method example

Background Recently, I encountered such a problem...