Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
Tags
- data
- 최댓값
- Dictionary
- dendrogram
- 최솟값
- string
- append()
- elbow method
- 덴드로그램
- list
- del
- wcss
- insert()
- len()
- hierarchical_clustering
- nan
- DataAccess
- DataFrame
- IN
- analizer
- sklearn
- 반복문
- matplotlib
- function
- Python
- pandas
- Machine Learning
- 분류 결과표
- numpy
- count()
Archives
- Today
- Total
개발공부
[MySQL] JOIN 과 LEFT JOIN 하는 방법과 예시 본문
customers 테이블
orders 테이블
JOIN 하기
두개 테이블을 하나로 합쳐서 가져오기
select *
from customers
join orders
on customers.id = orders.customer_id;
테이블의 이름을 줄여서 사용하는 방법
테이블명 바꿀이름(보통 첫글자를 따옴)
select *
from customers c
join orders o
on c.id = o.customer_id;
만일 컬럼의 이름이 중복되는 경우는컬럼명을 바꿔서 가져와야 한다.
위의 경우는 id가 서로 다르지만 동일한 컬럼처럼 보인다.
이런 경우는 아래처럼 바꿔야한다.
select c.id as customer_id, c.first_name, c.email,
o.id as order_id, o.amount, o.order_date
from customers c
join orders o
on c.id = o.customer_id;
LEFT JOIN
앞의 테이블은 모든 데이터를 가져오는 방법
모든 고객 데이터를 가져오되, 주문정보가 없는 고객도 나타나도록 가져오는 방법
select *
from customers c
left join orders o
on c.id = o.customer_id;
'Database > MySQL' 카테고리의 다른 글
[MySQL] NULL인지 아닌지 구별하는 IS NULL, IS NOT NULL (0) | 2022.05.17 |
---|---|
[MySQL] group by 의 having 사용법 (0) | 2022.05.17 |
[MySQL] 다른 테이블을 참조(Reference)하는 foreign key 설정하는 방법 (0) | 2022.05.17 |
[MySQL] NULL 값을 처리하는 함수 IFNULL() (0) | 2022.05.17 |
[MySQL] 조건문 IF (0) | 2022.05.17 |