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 5 years have passed since last update.

SQL JOINの方向あれこれ

0
Posted at

二つのTBLをJOINする時の結合方向を指定する。
引用元

INNER JOIN:両方の表で一致する行だけを表示させる

SELECT 列名1,列名2,〜列名n  どの列を表示させるか
FROM 「表名1 INNER JOIN 「表名2 ON 表名1.フィールド名 = 表名2.フィールド名
WHERE 抽出条件

  → 表名1と表明2の一致する行のみ

LEFT JOIN:左側に指定された表のすべての行が表示される

SELECT 列名1,列名2,〜列名n
FROM 「表名1 LEFT JOIN 「表名2 ON 表名1.フィールド名 = 表名2.フィールド名
WHERE 抽出条件

  → 左側の表名1のすべての行が表示される

RIGHT JOIN:右側に指定された表のすべての行が表示される

SELECT 列名1,列名2,〜列名n
FROM 「表名1 RIGHT JOIN 「表名2 ON 表名1.フィールド名 = 表名2.フィールド名
WHERE 抽出条件

   → 右側の表名2のすべての行が表示される

参考:INNER JOIN

SELECT *
FROM 売上表,顧客表
WHERE 売上表.顧客CD=顧客表.顧客CD

ORACLE-Refs

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?