Skip to Content
SQLポケットガイド 第4版
book

SQLポケットガイド 第4版

by Alice Zhao, 原 隆文
July 2024
Intermediate to advanced
328 pages
3h 24m
Japanese
O'Reilly Japan, Inc.
Content preview from SQLポケットガイド 第4版

4章クエリーの基礎

「クエリー」とはSELECT文の別名であり、6個の主要な句で構成されます。この章では、次のそれぞれの句について詳しく解説します。

  1. SELECT
  2. FROM
  3. WHERE
  4. GROUP BY
  5. HAVING
  6. ORDER BY

このほかに、MySQL、PostgreSQL、SQLiteでサポートされているLIMIT句についても解説します。

この章のコード例では、次の4つのテーブルを使います。それぞれの定義と内容については、「付録A サンプルテーブルの定義と内容」を参照してください。

waterfall
ミシガン州のアッパー半島に存在する滝
owner
滝の所有者
county
滝が存在している郡
tour
複数の立ち寄り先(滝)で構成されるツアー

次に示すのは、6個の主要な句を使ったサンプルクエリーです。その後にクエリーの結果が続いていますが、これは結果セット(result set)とも呼ばれます。

-- 一般公開されている2つ以上の滝を巡るツアー
SELECT   t.name AS tour_name,
         COUNT(*) AS num_waterfalls
FROM     tour t LEFT JOIN waterfall w
         ON t.stop = w.id
WHERE    w.open_to_public = 'y'
GROUP BY t.name
HAVING   COUNT(*) >= 2
ORDER BY tour_name;
tour_name  num_waterfalls
---------- ---------------
M-28                     6
Munising                 6
US-2                     4

データベースに対してクエリーを実行することは、データベースから(通常は1つまたは複数のテーブルから)データを検索することを意味します。 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

クリーンコードクックブック ―コードの設計と品質を改善するためのレシピ集

クリーンコードクックブック ―コードの設計と品質を改善するためのレシピ集

Maximiliano Contieri, 田中 裕一
推薦システム実践入門 ―仕事で使える導入ガイド

推薦システム実践入門 ―仕事で使える導入ガイド

風間 正弘, 飯塚 洸二郎, 松村 優也
Pythonクイックリファレンス 第4版

Pythonクイックリファレンス 第4版

Alex Martelli, Anna Martelli Ravenscroft, Steve Holden, Paul McGuire, 鈴木 駿, 株式会社クイープ

Publisher Resources

ISBN: 9784814400805Publisher Website