Error Code: 1055.Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'userinfo.

环境:mysql-8.0.15-winx64

问题描述:

Error querying database.  Cause: java.sql.SQLSyntaxErrorException: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘tt.from_id‘ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

关于叶神的头条资讯网站项目,自己在练习时,写了一个站内信,却一直获取站内信列表失败。前后对照代码都没错,很是急人!然后用MySQL workbench图示化出来发现,在写以下SQL语句时就出现了错误。对照着IDEA上的出错警示(下图1所示)

SELECT * FROM message group by conversation_id;

图1. IDEA上的出错警示

果然是DAO层的SQL语句出现了问题。但是我回过头来看,再三检查,发现明明没有问题呢【黑人问号脸】,于是百度搜索,发现真有不少相关的问题。

原来代码没错,是数据库的sql_mode出了问题。

参照参考2中解释【真心详细】,SQL模式默认情况下是only_full_group_by ,MySQL就会拒绝选择列表、条件或顺序列表引用的查询,这些查询将引用组中未命名的非聚合列,而不是在功能上依赖于它们。

为了一探究竟,于是乎,先后照着执行以下命令:

SHOW SESSION VARIABLES;SHOW GLOBAL VARIABLES;select @@sql_mode;

可见:session和global 的sql_mode的值都为:

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

按照参考2中解决办法操作时,在命令行发现出现了问题

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‘;

发现提示sql_mode不能被赋值为NO_AUTO_CREATE_USER,操作了一下set session sql_mode,也是同样的问题。

于是乎,那不行就不行呗,将NO_AUTO_CREATE_USER删去了,再次赋值。果然成功!

正确执行命令是:

set global sql_mode=‘STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION‘;
mysql> set session sql_mode=‘STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION‘;

这两个命令是去掉 sql_mode 的 ONLY_FULL_GROUP_BY模式的。故有效果。

另外,我还试了参考1中的办法,就是高赞的答案,执行如下:

SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,‘ONLY_FULL_GROUP_BY‘,‘‘));

然后发现也是不行,所以建议大家还是采用参考2中的方法吧!

参考:

1. https://stackoverflow.com/questions/41887460/select-list-is-not-in-group-by-clause-and-contains-nonaggregated-column-inc

2. 极力推荐:https://blog.csdn.net/fansili/article/details/78664267

3. http://blog.sina.com.cn/s/blog_3eba8f1c0102x75o.html

Error Code: 1055.Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'userinfo.

原文地址:https://www.cnblogs.com/gjmhome/p/11337329.html

时间: 2024-10-09 16:30:51

Error Code: 1055.Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'userinfo.的相关文章

MYSQL报错:1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column

1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'rpacloudsit.t.app_id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by MySQL有any_

mysql问题解决SELECT list is not in GROUP BY clause and contains nonaggregated column

今天在Ubuntu下的部署项目,发现一些好好的列表页面发生 1055:Expression #11 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'ppm_c.ppm_flow_starting_dealing.status' which is not functionally dependent on columns in GROUP BY clause; this is incompati

SELECT list is not in GROUP BY clause and contains nonaggregated

安装了mysql5.7,用group by 查询时抛出如下异常 SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'kanxf.o.down_uid' which is not functionally dependent on columns in GROU

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

原文链接:https://blog.csdn.net/hq091117/article/details/79065199 https://blog.csdn.net/allen_tsang/article/details/54892046 MySQL 5.7.5后only_full_group_by成为sql_mode的默认选项之一,这可能导致一些sql语句失效. 比如下表game: id group_id name score 1 A 小刚 20 2 B 小明 19 3 B 小花 17 4 C

mysql遇见Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggre的问题

报错如下: 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 in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by 问题出现的原因: MySQL 5.7.

解决mysql报错:- Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'information_schema.PROFILING.SEQ'

mysql执行报错: - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'information_schema.PROFILING.SEQ' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_fu

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

原因: https://blog.csdn.net/fansili/article/details/78664267 解决办法: 1:查看mysql配置文件位置 [root@localhost ~]# ps -ef | grep mysql mysql 838 1 0 02:21 ? 00:00:00 /usr/sbin/mysqld --defaults-file=/etc/my.cnf root 2035 1706 0 02:29 pts/0 00:00:00 grep --color=au

【MySQL】出现“SELECT list is not in GROUP BY clause and contains xxx”错误提示

需要设置为 sql_mode='NO_ENGINE_SUBSTITUTION' 设置方式: 1.MySQL客户端连接上数据库. 2.当前操作的数据切换成 mysql 3.执行 SELECT @@global.sql_mode 4.执行 SET GLOBAL sql_mode='NO_ENGINE_SUBSTITUTION'; 成功解决.

SELECT list is not in GROUP BY clause and contains

查询mysql 相关mode select @@global.sql_mode; 可以看到模式中包含了ONLY_FULL_GROUP_BY,只要没有这个配置即可. 我的Mysql版本是5.7.21,默认是带了ONLY_FULL_GROUP_BY模式. ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION 2.重设模式