티스토리 뷰

IA/DB

[mysql] join

kiostory 2019. 2. 27. 22:31




> select * from 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 |         2 |
|  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 |         4 |
+----+------------+-------------------+---------------------+-----------+
5 rows in set (0.0055 sec)




> select * from author;
+----+---------+---------------------------+
| id | name    | profile                   |
+----+---------+---------------------------+
|  1 | egoing  | developer                 |
|  2 | kio     | database administrator    |
|  3 | freebee | data scientist, developer |
|  4 | cookieg | CIO of cookio             |
+----+---------+---------------------------+





> select * from topic left join author on topic.author_id=author.id;
+----+------------+-------------------+---------------------+-----------+----+---------+---------------------------+
| id | title      | description       | created             | author_id | id | name    | profile                   |
+----+------------+-------------------+---------------------+-----------+----+---------+---------------------------+
|  1 | MySQL      | MySQL is...       | 2018-01-01 12:10:11 |         1 |  1 | egoing  | developer                 |
|  2 | Oracle     | Oracle is ....    | 2018-01-03 13:01:10 |         2 |  2 | kio     | database administrator    |
|  3 | SQL Server | SQL Server is ... | 2018-01-20 11:01:10 |         2 |  2 | kio     | database administrator    |
|  4 | PostgreSQL | PostgreSQL is ... | 2018-01-23 01:03:03 |         3 |  3 | freebee | data scientist, developer |
|  5 | MongoDB    | MongoDB is ...    | 2018-01-30 12:31:03 |         4 |  4 | cookieg | CIO of cookio             |
+----+------------+-------------------+---------------------+-----------+----+---------+---------------------------+


> select id,title,description,created,name,profile from topic left join author on topic.author_id=author.id;
ERROR: 1052 (23000): Column 'id' in field list is ambiguous



> select topic.id,title,description,created,name,profile from topic left join author on topic.author_id=author.id;
+----+------------+-------------------+---------------------+---------+---------------------------+
| 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 | kio     | database administrator    |
|  3 | SQL Server | SQL Server is ... | 2018-01-20 11:01:10 | kio     | database administrator    |
|  4 | PostgreSQL | PostgreSQL is ... | 2018-01-23 01:03:03 | freebee | data scientist, developer |
|  5 | MongoDB    | MongoDB is ...    | 2018-01-30 12:31:03 | cookieg | CIO of cookio             |
+----+------------+-------------------+---------------------+---------+---------------------------+

'IA > DB' 카테고리의 다른 글

[mysql] 초기 설치 후 샘플 데이터베이스 설치  (0) 2019.02.28
[mysql] centos 7 에서 mysql 설치  (0) 2019.02.28
[mysql] table column 명 변경  (0) 2019.02.26
[mysql] delete  (0) 2019.02.26
[mysql] update  (0) 2019.02.26
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/08   »
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
글 보관함