Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Ambiguous Groups #sqlap
Search
grimrose
February 05, 2014
Programming
0
910
Ambiguous Groups #sqlap
SQLアンチパターン読書会 「アンビギュアスグループ」
grimrose
February 05, 2014
Tweet
Share
More Decks by grimrose
See All by grimrose
だいたい10分くらいで 知った気になれる Vert.x 3.0 #渋谷Java / Shibuya.java #11
grimrose
0
1.9k
Syobochim should read book of modeling #syoboben
grimrose
0
1.8k
Gradleで始めるGroovy expand #jjug_ccc #ccc_r14
grimrose
4
6k
I wanna tell you about "Groovy Template"
grimrose
3
5.4k
Groovy Shell with Gradle
grimrose
0
5.2k
Shibuya.Java #07
grimrose
0
870
ぼっちプロジェクトとアジャイルサムライ
grimrose
0
280
Shibuya.Java #04
grimrose
1
630
I made out Gradle plug-in
grimrose
0
930
Other Decks in Programming
See All in Programming
Unicodeどうしてる? PHPから見たUnicode対応と他言語での対応についてのお伺い
youkidearitai
PRO
1
1.1k
インターン生でもAuth0で認証基盤刷新が出来るのか
taku271
0
190
AIで開発はどれくらい加速したのか?AIエージェントによるコード生成を、現場の評価と研究開発の評価の両面からdeep diveしてみる
daisuketakeda
1
970
AI前提で考えるiOSアプリのモダナイズ設計
yuukiw00w
0
220
疑似コードによるプロンプト記述、どのくらい正確に実行される?
kokuyouwind
0
380
Patterns of Patterns
denyspoltorak
0
1.4k
Rust 製のコードエディタ “Zed” を使ってみた
nearme_tech
PRO
0
140
責任感のあるCloudWatchアラームを設計しよう
akihisaikeda
3
160
KIKI_MBSD Cybersecurity Challenges 2025
ikema
0
1.3k
CSC307 Lecture 04
javiergs
PRO
0
650
余白を設計しフロントエンド開発を 加速させる
tsukuha
7
2.1k
dchart: charts from deck markup
ajstarks
3
990
Featured
See All Featured
Art, The Web, and Tiny UX
lynnandtonic
304
21k
We Are The Robots
honzajavorek
0
160
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
9.8k
For a Future-Friendly Web
brad_frost
182
10k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
410
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
9.5k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
0
290
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
122
21k
Google's AI Overviews - The New Search
badams
0
900
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
0
140
So, you think you're a good person
axbom
PRO
2
1.9k
The Curious Case for Waylosing
cassininazir
0
230
Transcript
SQLアンチパターン読書会 14章 「アンビギュアスグループ」 2014/02/06 @grimrose
目的 グループ内で最大値を持つ行
アンチパターン 非グループ化列を参照する
単一値の原則 Single-Value Rule
アンチパターンの見つけ方 _人人人人人人人人人人_ > エラーメッセージ <  ̄Y^Y^Y^Y^Y^Y^Y^Y^Y ̄ ※SQLiteとMySQLを除く
アンチパターンを用いてもよい場合 MySQLとSQLiteの場合 関係従属性を持つ列のみに クエリを実行するように注意
解決策 曖昧でない列を使用する
関数従属性のある列のみ クエリから曖昧な列を排除
相関サブクエリ • 読みやすい • コードの記述も簡単 • パフォーマンスに注意
導出テーブル • 相関サブクエリよりパフォーマ ンスが高い • テンポラリテーブル
JOIN • 大量のデータに対するパフォーマンス が重要な場合 • パフォーマンスの測定してね
他の列に対しても集約関数 単一値の原則
グループ毎に全ての値を連結 • GROUP_CONCAT関数 ◦ MySQL, SQLite • PostgreSQLの場合 ◦ ARRAY_TO_STRING(ARRAY_AGG(any),
',') • カスタム関数 • ストアドプロシージャ
まとめ 曖昧なクエリ結果を避けるために、 単一値の原則に従う