Skip to content

Instantly share code, notes, and snippets.

@nikuyoshi
Created May 15, 2014 16:34
Show Gist options
  • Save nikuyoshi/e365cdbc8b77edf6de41 to your computer and use it in GitHub Desktop.
Save nikuyoshi/e365cdbc8b77edf6de41 to your computer and use it in GitHub Desktop.
副問い合わせでGROUP BY句を使って、主問い合わせでもGROUP BY句を使った時のクエリについて
SELECT hoge FROM A WHERE fuga IN (SELECT fuga FROM B WHERE X ='TEST' GROUP BY fuga) GROUP BY hoge;

上記のクエリーが超遅い、っていうかいつまで経っても結果が返ってこないので下記のクエリーに変更したらあっさりいった。

SELECT hoge FROM A WHERE fuga IN (SELECT fuga FROM B WHERE X ='TEST') GROUP BY hoge;

サブクエリー内のGROUP BYって駄目なんだっけ…?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment