티스토리 뷰

Database2 - Mysql

2020-03-23
2nd day


JOIN

topic 테이블 ↓

id title description created author_id
1 MySQL MySQL is... 2018-01-01 12:10:11 1
2 Oracle Oracle is... 2018-01-03 13:01:10 1
3 SQL Server SQL Server is... 2018-01-20 11:01:10 2
4 PostgreSQL PostgreSQL is... 2018-01-23 01:03:03 3
5 MongoDB MongoDB is... 2018-01-30 12:31:03 1

 

author 테이블 ↓

id name profile
1 egoing developer
2 duru data administrator
3 taeho data scientist, developer

 

author_idauthor.id를 일치시키기 위해 아래 쿼리 실행

SELECT topic.id AS 'topic.id', -- AS : 이름지정
       title, 
       description, 
       created, 
       name, 
       profile 
       FROM topic 
       LEFT JOIN author -- INNER, LEFT, RIGHT 등등.. 벤다이어그램을 생각
       ON topic.author_id=author.id; -- topic테이블과 author테이블의 공통 키값을 기준으로 한다.

 

결과물

topic.id title description created name profile
1 MySQL MySQL is... 2018-01-01 12:10:11 egoing developer
2 Oracle Oracle is... 2018-01-03 13:01:10 egoing developer
5 MongoDB MongoDB is... 2018-01-30 12:31:03 egoing developer
3 SQL Server SQL Server is... 2018-01-20 11:01:10 duru data administrator
4 PostgreSQL PostgreSQL is... 2018-01-23 01:03:03 taeho data scientist, developer

 

참고 이미지

INNER JOIN

img2

LEFT, RIGHT JOIN

img1

Link

자료출처 및 자세한 설명

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/12   »
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
글 보관함