본문 바로가기

BeADeveloper/DBstudy

관계형 데이터의 필요성 / 테이블 분리 - JOIN

데이터 중복을 제거.

> 데이터가 많아지면 많아질수록 처리 속도 (퍼포먼스) 와 유지보수가 어려워짐

 

하나의 표에서 직관적으로 데이터 항목들을 볼 수 있는 장점을 버리는 효과

> 하지만 우리가 상상하는건, 수없는 데이터의 집합

> SQL 을 통해 한눈에 데이터를 볼 수 있는 명령도 가능

 

 

관계형 데이터 베이스의 꽃.. JOIN

A. join point 를 찾아라!

B. 아래 예제에서는, author_id of topic == id of author

 

TABLE JOIN

mysql> SELECT*FROM topic LEFT JOIN author ON topic.author_id = author.id;

topic table의 왼쪽에, author table을 join 시키는데, 기준은 [topic table의 author_id == author table의 id]

 

(Primary Key = id), author와 topic table로 나누어진 data를...
JOIN! > 첫 번째 줄은 오타

JOIN : delete useless column

mysql> SELECT topic.id, title, description,created, name, profile FROM topic LEFT JOIN author ON topic.author_id = author.id;

필요없는 cloumn을 없앨수도 있습니다.

JOIN : change cloumn name

mysql> SELECT topic.id AS topic_id, title, description,created, name, profile FROM topic LEFT JOIN author ON topic.author_id = author.id;

column name을 변경할 수도 있구요!

 

Change some items

mysql> UPDATE author SET profile='database administrator' where id = 2;

change author's profile