PostgreSQL outer join
2025. 1. 29. 10:41ㆍData/PostgreSQL
Left outer join: a 기준으로 다 나옴
SELECT
a.id AS table_a_id,
a.name AS table_a_name,
b.id AS table_b_id,
b.description AS table_b_description
FROM table_a a
LEFT OUTER JOIN table_b b ON a.id = b.a_id;
table_a_id | table_a_name | table_b_id | table_b_description
-----------+-------------+------------+----------------------
1 | Apple | 1 | Fruit
2 | Carrot | NULL | NULL
3 | Orange | 3 | Citrus
Right outer join: b 기준으로 다 나옴
SELECT
a.id AS table_a_id,
a.name AS table_a_name,
b.id AS table_b_id,
b.description AS table_b_description
FROM table_a a
RIGHT OUTER JOIN table_b b ON a.id = b.a_id;
table_a_id | table_a_name | table_b_id | table_b_description
-----------+-------------+------------+----------------------
1 | Apple | 1 | Fruit
NULL | NULL | 2 | Vegetable
3 | Orange | 3 | Citrus
Full outer join: 양쪽 다 나옴
SELECT
a.id AS table_a_id,
a.name AS table_a_name,
b.id AS table_b_id,
b.description AS table_b_description
FROM table_a a
FULL OUTER JOIN table_b b ON a.id = b.a_id;
table_a_id | table_a_name | table_b_id | table_b_description
-----------+-------------+------------+----------------------
1 | Apple | 1 | Fruit
2 | Carrot | NULL | NULL
3 | Orange | 3 | Citrus
NULL | NULL | 2 | Vegetable
'Data > PostgreSQL' 카테고리의 다른 글
PostgreSQL WITH RECURSIVE 배열로 데이터 전달하기 (0) | 2025.01.30 |
---|---|
PostgreSQL WITH RECURSIVE과 ARRAY를 사용하여, hierarchy 구조 테이블 데이터 보여주기 (0) | 2025.01.29 |
PostgreSQL 'desc'도 키워드임 (0) | 2025.01.04 |
PostgreSQL update문 처리 (0) | 2024.12.28 |
PostgreSQL 컬럼명에 'table'을 사용하면 에러 발생함 (0) | 2024.12.28 |