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
880
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.8k
Syobochim should read book of modeling #syoboben
grimrose
0
1.8k
Gradleで始めるGroovy expand #jjug_ccc #ccc_r14
grimrose
4
5.9k
I wanna tell you about "Groovy Template"
grimrose
3
5.3k
Groovy Shell with Gradle
grimrose
0
5.2k
Shibuya.Java #07
grimrose
0
840
ぼっちプロジェクトとアジャイルサムライ
grimrose
0
260
Shibuya.Java #04
grimrose
1
610
I made out Gradle plug-in
grimrose
0
910
Other Decks in Programming
See All in Programming
CLI ツールを Go ライブラリ として再実装する理由 / Why reimplement a CLI tool as a Go library
ktr_0731
3
560
What's new in AppKit on macOS 26
1024jp
0
180
TypeScriptでDXを上げろ! Hono編
yusukebe
3
870
それ CLI フレームワークがなくてもできるよ / Building CLI Tools Without Frameworks
orgachem
PRO
11
2.6k
脱Riverpod?fqueryで考える、TanStack Queryライクなアーキテクチャの可能性
ostk0069
0
570
Prompt Engineeringの再定義「Context Engineering」とは
htsuruo
0
110
PHPカンファレンス関西2025 基調講演
sugimotokei
5
990
Quality Gates in the Age of Agentic Coding
helmedeiros
PRO
1
110
プロダクトという一杯を作る - プロダクトチームが味の責任を持つまでの煮込み奮闘記
hiliteeternal
0
280
SQLアンチパターン第2版 データベースプログラミングで陥りがちな失敗とその対策 / Intro to SQL Antipatterns 2nd
twada
PRO
34
9.9k
なぜあなたのオブザーバビリティ導入は頓挫するのか
ryota_hnk
3
510
0から始めるモジュラーモノリス-クリーンなモノリスを目指して
sushi0120
0
160
Featured
See All Featured
A designer walks into a library…
pauljervisheath
207
24k
The Invisible Side of Design
smashingmag
301
51k
Documentation Writing (for coders)
carmenintech
72
4.9k
Facilitating Awesome Meetings
lara
54
6.5k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
15
1.6k
Site-Speed That Sticks
csswizardry
10
720
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
229
22k
Into the Great Unknown - MozCon
thekraken
40
1.9k
For a Future-Friendly Web
brad_frost
179
9.8k
Raft: Consensus for Rubyists
vanstee
140
7k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
8
380
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
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),
',') • カスタム関数 • ストアドプロシージャ
まとめ 曖昧なクエリ結果を避けるために、 単一値の原則に従う