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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
640
I made out Gradle plug-in
grimrose
0
930
Other Decks in Programming
See All in Programming
HTTPプロトコル正しく理解していますか? 〜かわいい猫と共に学ぼう。ฅ^•ω•^ฅ ニャ〜
hekuchan
2
680
Kotlin Multiplatform Meetup - Compose Multiplatform 외부 의존성 아키텍처 설계부터 운영까지
wisemuji
0
190
CSC307 Lecture 03
javiergs
PRO
1
490
開発者から情シスまで - 多様なユーザー層に届けるAPI提供戦略 / Postman API Night Okinawa 2026 Winter
tasshi
0
200
高速開発のためのコード整理術
sutetotanuki
1
390
React 19でつくる「気持ちいいUI」- 楽観的UIのすすめ
himorishige
11
6k
Smart Handoff/Pickup ガイド - Claude Code セッション管理
yukiigarashi
0
130
AIによる高速開発をどう制御するか? ガードレール設置で開発速度と品質を両立させたチームの事例
tonkotsuboy_com
7
2.1k
AWS re:Invent 2025参加 直前 Seattle-Tacoma Airport(SEA)におけるハードウェア紛失インシデントLT
tetutetu214
2
110
CSC307 Lecture 07
javiergs
PRO
0
550
Amazon Bedrockを活用したRAGの品質管理パイプライン構築
tosuri13
4
260
Grafana:建立系統全知視角的捷徑
blueswen
0
330
Featured
See All Featured
The Mindset for Success: Future Career Progression
greggifford
PRO
0
230
For a Future-Friendly Web
brad_frost
182
10k
The agentic SEO stack - context over prompts
schlessera
0
630
How STYLIGHT went responsive
nonsquared
100
6k
Documentation Writing (for coders)
carmenintech
77
5.2k
Believing is Seeing
oripsolob
1
53
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
130
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3k
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
180
Why Our Code Smells
bkeepers
PRO
340
58k
From π to Pie charts
rasagy
0
120
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
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),
',') • カスタム関数 • ストアドプロシージャ
まとめ 曖昧なクエリ結果を避けるために、 単一値の原則に従う