ONLY_FULL_GROUP_BY未设置,但仍有错误1140 [英] ONLY_FULL_GROUP_BY not set but still have Error 1140

查看:197
本文介绍了ONLY_FULL_GROUP_BY未设置,但仍有错误1140的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在最终确定我的网站的实施情况,但现在我遇到了一个网上发现的问题,我并没有在本地。



我收到这个错误:

 失败:GROUP列(MIN(),MAX(),COUNT(),...)与GROUP列的混合是非法的没有GROUP BY子句

SQL查询的结果

我在网上搜索了许多论坛,大多数用户建议更改我不能/不想要的查询,或者他们说可能是在sql-mode中:enabled ONLY_FULL_GROUP_BY 服务器



我的sql-mode在我的在线服务器上是空的(我可以通过查询 select @@ sql_mode;
更确切地说,我把 sql_mode =''放入my.cnf中。



但问题仍然存在。



这是由于我的服务器版本的mysql 5.0.44在线和本地5.1.32 (我没有这个bug ...)?

解决方案

是。你是对的。这是由于 MySQL版本造成的。

检查我的答案此处



如何检查MySQL版本?

  mysql> SELECT version(); 
+ ----------- +
|版本()|
+ ----------- +
| 5.5.28 |
+ ----------- +
1行(0.00秒)

对于测试sql_mode ONLY_FULL_GROUP_BY ,我使用两列<$ c $创建了表 patient c> id,名称并插入记录。记住sql_mode ONLY_FULL_GROUP_BY 不是默认设置,你需要设置,如果你想。
$ b 1)MySQL版本 5.0.45-community-nt

  SELECT name,MAX(id)FROM patient; 
ERROR 1140(42000):如果没有GROUP BY子句,则GROUP列(MIN(),MAX(),COUNT(),...)与GROUP列的混合是非法的

失败了,将sql_mode设置为 ONLY_FULL_GROUP_BY 为没有意义它将不允许未在GROUP BY子句中命名的非聚合列。
$ b 2)MySQL版本 5.1.40-community

 的MySQL>来自患者的SELECT名称,MAX(id); 
+ ---------- + -------- +
| MAX(id)|名称|
+ ---------- + -------- +
| 33 | aniket |
+ ---------- + -------- +
1行(0.03秒)

然后设置sql_mode ONLY_FULL_GROUP_BY

 的MySQL>设置sql_mode ='ONLY_FULL_GROUP_BY'; 
查询OK,0行受影响(0.00秒)

mysql>来自患者的SELECT名称,MAX(id);
ERROR 1140(42000):如果没有GROUP BY子句,则GROUP列(MIN(),MAX(),COUNT(),...)与GROUP列的混合是非法的



<3> MySQL版本 5.5.28

 的MySQL>来自患者的SELECT名称,MAX(id); 
+ ---------- + -------- +
| MAX(id)|名称|
+ ---------- + -------- +
| 33 | aniket |
+ ---------- + -------- +
1行(0.03秒)

然后设置sql_mode ONLY_FULL_GROUP_BY

 的MySQL>设置sql_mode ='ONLY_FULL_GROUP_BY'; 
查询OK,0行受影响(0.00秒)

mysql>来自患者的SELECT名称,MAX(id);
ERROR 1140(42000):如果没有GROUP BY子句,则GROUP列(MIN(),MAX(),COUNT(),...)与GROUP列的混合是非法的

结论

查询在版本5.0.45上失败,并且在5.1.40,5.5.28和5.1.32之后成功(正如您提到的那样)。
在MySQL版本之前 5.1.10 (不确定)查询而不是 GROUP BY 失败,无论sql_mode ONLY_FULL_GROUP_BY 是否设置。

一些有趣的错误和sql_mode常见问题链接


  1. ONLY_FULL_GROUP_BY sql模式过于严格

  2. sql-mode:只有完整的分组模式才能工作

  3. MySQL 5.0 FAQ:服务器SQL模式


I am finalizing the implementation of my website but now I have a problem that occurs online that I have not locally.

I get this error:

failed: Mixing of GROUP columns (MIN (), MAX (), COUNT (), ...) with no GROUP columns is illegal if there is no GROUP BY clause

result of a SQL query

I searched in lot of forums on the net, most users advise to change the query that I can not / do not want, or they say it was probably in the sql-mode: enabled ONLY_FULL_GROUP_BY of the server

My sql-mode is empty on my server online (I can see with the query select @@sql_mode;) More to be sure, I put sql_mode='' in my.cnf.

But the problem remains.

Is this due to my version of mysql 5.0.44 on my server online and locally 5.1.32 (which I do not have this bug ...)?

解决方案

Yes. You are right. This happens because of MySQL version.
Check my answer here

How to check MySQL version?

mysql> SELECT version();
+-----------+
| version() |
+-----------+
| 5.5.28    |
+-----------+
1 row in set (0.00 sec)    

For testing sql_mode ONLY_FULL_GROUP_BY, I created table patient with two columns id, name and inserted records. Remember sql_mode ONLY_FULL_GROUP_BY is not default set, you need to set if you want.

1)MySQL version 5.0.45-community-nt

SELECT name, MAX(id) FROM patient;
ERROR 1140 (42000): Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause  

It failed, there was no point in setting the sql_mode to ONLY_FULL_GROUP_BY as it won't allow nonaggregated columns that are not named in the GROUP BY clause.

2)MySQL version 5.1.40-community

mysql> SELECT name, MAX(id) from patient;
+----------+--------+
| MAX(id)  | name   |
+----------+--------+
|       33 | aniket |
+----------+--------+
1 row in set (0.03 sec)  

Then after setting sql_mode ONLY_FULL_GROUP_BY

mysql> set sql_mode = 'ONLY_FULL_GROUP_BY';
Query OK, 0 rows affected (0.00 sec)

mysql> SELECT name, MAX(id) from patient;
ERROR 1140 (42000): Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause  

3)MySQL version 5.5.28

mysql> SELECT name, MAX(id) from patient;
+----------+--------+
| MAX(id)  | name   |
+----------+--------+
|       33 | aniket |
+----------+--------+
1 row in set (0.03 sec)  

Then after setting sql_mode ONLY_FULL_GROUP_BY

mysql> set sql_mode = 'ONLY_FULL_GROUP_BY';
Query OK, 0 rows affected (0.00 sec)

mysql> SELECT name, MAX(id) from patient;
ERROR 1140 (42000): Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause  

Conclusion

As you can see query failed on version 5.0.45, and succeed on/after 5.1.40, 5.5.28 and 5.1.32 (as you mentioned in question). Before MySQL version 5.1.10(not sure) query without GROUP BY fails irrespective of sql_mode ONLY_FULL_GROUP_BY set or not.

Some interesting bugs and sql_mode faq link

  1. ONLY_FULL_GROUP_BY sql mode is overly restrictive
  2. sql-mode: only full group by mode not working
  3. MySQL 5.0 FAQ: Server SQL Mode

这篇关于ONLY_FULL_GROUP_BY未设置,但仍有错误1140的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆