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】内部結合( INNER JOIN )とは

Posted at

#内部結合( INNER JOIN )とは
互いのテーブルに存在するデータのみを結合
※ON ( 条件文 )で指定したデータがあるかないか

##構文

SELECT      出力テーブル列名
FROM        対象テーブル1
INNER JOIN  対象テーブル2
ON          テーブル1.列名 = テーブル2.列名;

##実際にやってみる
name テーブル

id name code
1 うさぎ 1
2 へび 2
3 ぱんだ 1
4 らいおん 3

info テーブル

|code |info |
|---|---|---|
|1 |かわいい |
|2 |かっこいい |

SELECT name.id,
       name.name,
       info.code,
       info.info
FROM name
INNER JOIN info
ON name.code = info.code;

###実行結果

id name code info
1 うさぎ 1 かわいい
2 へび 2 かっこいい
3 ぱんだ 1 かわいい

らいおんの name.code と一致するデータが info.code に存在しなかった為、らいおんは結合されない

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?