티스토리 뷰
반응형
#동등조인
select username,saleprice
from customer C, orders O
where c.custid = O.custid;
이너조인(동등조인과 같다)
#inner join
select username, saleprice
from customer C
join orders O
on C.custid=O.custid;
ON의 조건을 기준으로 join이라는 명령어를 써준다.
외부 왼쪽 조인
외부조인
도서를 구매하지 않은 고객을 포함해 고객 이름/전화번호와 주문도서의 판매가격을 출력
select username, orders.saleprice
from customer
left outer join orders
on customer.custid=orders.custid;
오른쪽 외부조인
오른쪽(orders.custid)를 중심으로 조인을 하기 때문에 주문이 있는 사람만 출력됨
select username, orders.saleprice
from customer
right outer join orders
on customer.custid=orders.custid;
크로스 조인
select customer.username, saleprice,orderdate
from customer
cross join orders
on customer.custid=orders.custid;
하나만 나오는 것이 아니라 박지성, 김연아 등이 여러번 나온다.
일치하는 모든 결과를 보여준다.
not in과 in 연산을 이용해 minus와 intersect 연산을 할 수 있다.
(MYSQL에서는 minsu와 intersect를 지원하지 않는다.)
실습
유니온 연산
select username,phone
from customer
where address like '%서울%'
UNION
select username,phone
from customer
where custid in (select custid from orders);
반응형
'새싹 > 새싹데이터' 카테고리의 다른 글
21. SQL 분석과 통계 사용하기 (0) | 2022.05.24 |
---|---|
20. SQL 집계 이해하기 (0) | 2022.05.22 |
18. SQL 서브쿼리 (0) | 2022.05.20 |
18. 내장함수, 문자/숫자/날짜 연산 이해 (0) | 2022.05.20 |
16. SQL 스키마 생성하고 테이블 데이터 탐색하기 (0) | 2022.05.18 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 뇌와행동의기초
- 인프런
- 열혈프로그래밍
- c++
- 인지부조화
- 일본어문법무작정따라하기
- 사회심리학
- 심리학
- 강화학습
- 보세사
- 백준
- 데이터분석
- C/C++
- 류근관
- 일문따
- 통계
- 파이썬
- 회계
- 윤성우
- 여인권
- 통계학
- Python
- C
- jlpt
- 일본어
- K-MOOC
- 티스토리챌린지
- 코딩테스트
- 오블완
- stl
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함
반응형