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 の使用を開始

第4章. セレクト

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

データベースとSQLを扱うとき、最も一般的なのタスクは、1つ以上のテーブルからデータを要求し、それを表示することである。SELECT 。しかし、SELECT は単にデータを取得して表示するだけでなく、それ以上のことができる。これからの章で学ぶように、我々はこのデータを意味のある方法で変換し、何百万ものレコードから強力なサマリーを構築することができる。

しかしその前に、1つのテーブルからSELECT 、その中で式を構成する方法を学ぶ。

SQLでデータを取得する

まだ SQLiteStudio を開いていない場合は、上部メニューの Tools→Open SQL Editor をクリックし、前章で述べたようにrexon_metals データベースが開いていることを確認する。 SQLiteStudio のワークスペースは図 4-1 のようになる。SQLワークスペースはSQL EditorペインとQuery Resultsペインの2つのペインに分かれている。

The SQL editor
図4-1. SQLワークスペース

SQLエディター・ペインにはSQLを書き、クエリ結果ペインにはSQLの結果が表示される。

最初のSQL文を書いてみよう。 最も一般的なSQL演算子はSELECT 。テーブルからデータを取り出し、その結果を表示する。SQLエディタ・ペインをクリックして、以下の文を書く:

SELECT * FROM CUSTOMER;

青い三角ボタンをクリックするか、F9キーを押してSQLを実行する。

最初のクエリを実行し、その結果が下のペインに表示されているはずである(図4-2)

Running a SELECT query
図4-2. SELECTクエリを実行する

何が起こったのかを正確に説明しよう。SELECT 、テーブルからどのカラムを取り出すかを選択できる。つまり、ここに示したSQLの最初の部分は、"Select all columns"(すべての列を選択する)と読み取り、*はすべての列を指定するプレースホルダーである:

SELECT * FROM CUSTOMER;

そして、これらのカラムをCUSTOMER

SELECT * FROM CUSTOMER;

このSELECT ステートメントを実行すると、CUSTOMER テーブルからすべての列が表示される(図4-3)。

Selecting all records from the CUSTOMER table
図4-3. CUSTOMER テーブルからすべてのレコードを選択する

SELECT 、すべての列を引っ張ってくる必要はない。興味のあるカラムだけを選んで取り出すこともできる。以下のクエリでは、CUSTOMER_IDNAME のカラムだけを取り出す:

SELECT CUSTOMER_ID
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