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?

学習記録

Last updated at Posted at 2024-07-17

内部結合

JOIN/INNER JOIN

両方のテーブルにあるデータのみを取り出す。

order_id user_id product
1 1 Laptop
2 2 Smartphone
3 1 Headphones
4 NULL Monitor
5 3 Tablet
SELECT 
    users.username,
    orders.product
FROM 
    users
INNER JOIN 
    orders
ON 
    users.user_id = orders.user_id;

外部結合

LEFT JOIN/RIGHT JOIN/OUTER JOIN

どちらかのテーブルにデータがあれば、取り出す

order_id user_id product
1 1 Laptop
2 2 Smartphone
3 1 Headphones
4 NULL Monitor
5 3 Tablet

SELECT 
    users.username,
    orders.product
FROM 
    users
LEFT JOIN 
    orders
ON 
    users.user_id = orders.user_id;

まとめ

NULLを許容するかしないかって事かな

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?