[Inflearn] DATABASE 1&2 - MySQL (Egoing Lee)
섹션 5를 듣고 정리하였다.
1, 2, 5행의 author, profile 열이 중복된다.
이전 topic 테이블에 존재하던 중복된 데이터들은 사라지고, 각 데이터들에 대한 author 테이블의 식별자인 id 값으로 대체되었다.author 중 egoing을 e+going으로 바꿔야 할 때
기존 데이터베이스는 하나의 테이블만으로도 모든 정보를 파악할 수 있지만,
관계형 데이터베이스는 하나의 테이블에서 다른 테이블을 참조하게 되므로 별도의 표를 추가적으로 열어서 정보를 확인해야 한다.
RENAME TABLE topic TO topic_backup;
기존 테이블의 이름을 topic에서 topic_backup으로 변경한다.

INSERT INTO `author` VALUES (1,'egoing','developer');
INSERT INTO `author` VALUES (2,'duru','database administrator');
INSERT INTO `author` VALUES (3,'taeho','data scientist, developer');
INSERT INTO `topic` VALUES (1,'MySQL','MySQL is...','2018-01-01 12:10:11',1);
INSERT INTO `topic` VALUES (2,'Oracle','Oracle is ...','2018-01-03 13:01:10',1);
INSERT INTO `topic` VALUES (3,'SQL Server','SQL Server is ...','2018-01-20 11:01:10',2);
INSERT INTO `topic` VALUES (4,'PostgreSQL','PostgreSQL is ...','2018-01-23 01:03:03',3);
INSERT INTO `topic` VALUES (5,'MongoDB','MongoDB is ...','2018-01-30 12:31:03',1);
위 코드를 모두 입력한 결과

SELECT * FROM topic LEFT JOIN author ON topic.author_id = author.id;
topic 테이블의 author_id의 값과 author 테이블의 id의 값이 같아지도록
topic 테이블에 author 테이블을 합성한다.

author_id와 id열 제외하고 출력하기SELECT topic.id,title,description,created,name,profile FROM topic LEFT JOIN author ON topic.author_id = author.id;

SELECT id,title,description,created,name,profile FROM topic LEFT JOIN author ON topic.author_id = author.id; 를 입력했을 경우id열의 이름을 topic_id로 바꾸기SELECT topic.id AS topic_id ...
