0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

SQL データ加工の基礎的な方法Ⅱ

Last updated at Posted at 2020-08-17

◆サブクエリ
SELECT name
FROM players
WHERE gols >(
SELECT goals
FROM players
WHERE name = "中田"
);

サブクエリで「中田の得点数を取得」
「中田の得点数を取得」より多い選手を取得している

◆AS
カラム名 AS "名前" 
カラム名に定義する名前を指定

複数のカラム名を接続する際には、
カラム名 AS "名前",カラム名 AS "名前"

◆テーブルを紐づける
テーブルを紐づけるためには外部キーと主キーを指定することで
紐づけることができる。

◆join

SELECT *
FROM テーブルA
JOIN テーブルB
ON テーブルA.カラム名 = テーブルB.カラム名;

◆全体実行順序の確認
キャプチャ.PNG

◆LEFT JOIN

SELECT *
FROM players
LEFT JOIN teams
ON テーブルA.カラム名 = テーブルB.カラム名;

◆複数テーブルのJOIN

SELECT *
FROM players
JOIN countries
ON テーブルA.カラム名 = テーブルB.カラム名;
LEFT JOIN teams
ON テーブルC.カラム名 = テーブルD.カラム名;

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?