LoginSignup
5
4

More than 5 years have passed since last update.

MySQLで実行環境によってQuery errorになる問題(only_full_group_by)

Last updated at Posted at 2016-09-23

サーバー上で動いている資源をローカルで動かそうとすると以下のエラーが発生した。

Query error: Expression #33 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'hogehoge' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

当初、資源が違うのでは?とも思ったがどうやらMysqlのVersionによる設定の問題らしい。
キーワードはエラーの最後に出ているsql_mode=only_full_group_by
調べてみるとMysqlのVersion5.6ではONLY_FULL_GROUP_BYがデフォルトでオフだったものが
Mysql5.7からオンになったとの事。

この設定のせいでgroup_byで非集約でも上手い事(?)実行してくれていたらしい。
実際に実行されているSQLを見てみると「なんでコレで動いてんの。。。」的なSQLが書いてあった。

5.6以前のVersionでもonly_full_group_byはオフにしておくのが無難、と言うか
そもそもちゃんとしたSQLを書けば良いというだけのお話ではある。

5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4