Skip to Content
SQL の使用を開始
book

SQL の使用を開始

by Thomas Nield
May 2025
Intermediate to advanced
134 pages
1h 43m
Japanese
O'Reilly Media, Inc.
Content preview from SQL の使用を開始

第8章. 結合

この作品はAIを使って翻訳されている。ご意見、ご感想をお待ちしている:translation-feedback@oreilly.com

テーブルを縫い合わせる

結合はSQLの定義機能であり、他のデータ技術とは一線を画している。 これまでに扱った内容にある程度慣れていることを確認し、次に進む前にじっくりと練習と復習をしよう。

本書の冒頭、リレーショナルデータベースについて議論したときに戻ってみよう。正規化された」データベースには、他のテーブルを指すフィールドを持つ点 がよくあることを覚えているだろうか?例えば、CUSTOMER_ID フィールドを持つCUSTOMER_ORDER テーブルを考えてみよう(図8-1)。

The CUSTOMER_ORDER table has a CUSTOMER_ID field
図8-1. CUSTOMER_ORDER テーブルには CUSTOMER_ID フィールドがある。

このCUSTOMER_ID フィールドは、CUSTOMER テーブルで検索するためのキーを与えてくれる。これを知っていれば、CUSTOMER テーブルにもCUSTOMER_ID フィールドがあっても不思議ではないだろう(図8-2)。

The CUSTOMER table has a CUSTOMER_ID key field that can be used to get customer information
図8-2. CUSTOMERテーブルにはCUSTOMER_IDキー・フィールドがあり、これを使用して顧客情報を取得できる。

エクセルのVLOOKUPのように、このテーブルから注文の顧客情報を取り出すことができる。

これはCUSTOMER_ORDER テーブルとCUSTOMER テーブルの間の関係の 例である。CUSTOMERCUSTOMER_ORDERであると言える。CUSTOMER_ORDER は情報をCUSTOMER に依存しているので、CUSTOMERである。逆に、CUSTOMER は情報をCUSTOMER_ORDER に依存していないので、 の子にはなれない。 図8-3の図はこの関係を示している。矢印は、CUSTOMERCUSTOMER_ID を介してCUSTOMER_ORDER に顧客情報を供給していることを示している。

CUSTOMER is the parent to CUSTOMER_ORDER, because CUSTOMER_ORDER depends on it for CUSTOMER information
図 8-3. CUSTOMER_ORDER は CUSTOMER_ORDER の親であり、CUSTOMER_ORDER はCUSTOMER_ORDER に CUSTOMER 情報を依存しているからである。

リレーションシップで考慮すべきもう1つの側面は、子テーブルのいくつのレコードが、親テーブルの1つのレコードに紐付けられるかということである。 CUSTOMERCUSTOMER_ORDER テーブルを例にとると、1対多のリレーションシップで、1つの顧客レコードが複数の注文に紐づくことがわかる。CUSTOMER_ID 3 の顧客 "Re-Barre Construction "は3つの注文と結びついている

図8-4. CUSTOMER と ...
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

MySQL クックブック、第 4 版

MySQL クックブック、第 4 版

Sveta Smirnova, Alkin Tezuysal
コンピュータビジョンのための実践機械学習 ―モデルアーキテクチャからMLOpsまで

コンピュータビジョンのための実践機械学習 ―モデルアーキテクチャからMLOpsまで

Valliappa Lakshmanan, Martin Görner, Ryan Gillard, 大山 匠, 松田 晃一

Publisher Resources

ISBN: 9798341651029