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

A brief discussion on the differences between FTP, FTPS and SFTP

Table of contents Introduction to FTP, FTPS and S...

How to install vncserver in Ubuntu 20.04

Ubuntu 20.04 has been officially released in Apri...

Share some uncommon but useful JS techniques

Preface Programming languages ​​usually contain v...

Detailed explanation on how to install MySQL database on Alibaba Cloud Server

Preface Since I needed to install Zookeeper durin...

How to use Baidu Map API in vue project

Table of contents 1. Register an account on Baidu...

Problems and solutions for installing Docker on Alibaba Cloud

question When installing Docker using Alibaba Clo...

Native js implements a minesweeper game with custom difficulty

This article example shares the specific code of ...

Detailed explanation of Vue custom instructions

Table of contents Vue custom directive Custom dir...

Pure CSS custom multi-line ellipsis problem (from principle to implementation)

How to display text overflow? What are your needs...

Comparative Analysis of MySQL Binlog Log Processing Tools

Table of contents Canal Maxwell Databus Alibaba C...

Using react-beautiful-dnd to implement drag and drop between lists

Table of contents Why choose react-beautiful-dnd ...

Batch replace part of the data of a field in Mysql (recommended)

Batch replace part of the data of a field in MYSQ...