처음으로 join 완성^^ 정보
처음으로 join 완성^^관련링크
본문
처음으로 join 완성^^
MySql Left Right 조인Projects 와 Buyers 2개의 테이블을 생성한다.
mysql> SELECT * FROM products;
+----+--------------+--------------+
| id | product_name | manufacturer |
+----+--------------+--------------+
| 1 | Shoes | Company1 |
| 2 | Laptop | Company2 |
| 3 | Monitor | Company3 |
| 4 | DVD | Company4 |
+----+--------------+--------------+
4 rows in set (0.00 sec)
Table buyers:
mysql> SELECT * FROM buyers;
+----+------+------------+----------+
| id | pid | buyer_name | quantity |
+----+------+------------+----------+
| 1 | 1 | Steve | 2 |
| 2 | 2 | John | 1 |
| 3 | 3 | Larry | 1 |
| 4 | 3 | Michael | 5 |
| 5 | NULL | Steven | NULL |
+----+------+------------+----------+
5 rows in set (0.00 sec)
Left Join
mysql> SELECT buyer_name, quantity, product_name FROM buyers LEFT JOIN products ON
buyers.pid=products.id;
+------------+----------+--------------+
| buyer_name | quantity | product_name |
+------------+----------+--------------+
| Steve | 2 | Shoes |
| John | 1 | Laptop |
| Larry | 1 | Monitor |
| Michael | 5 | Monitor |
| Steven | NULL | NULL |
+------------+----------+--------------+
5 rows in set (0.00 sec)
* 가장많이 사용하는 조인
* 조인하는 쪽의 데이터가 존재하지 않더라도 Null로 조인한다.
Right Join
mysql> SELECT buyer_name, quantity, product_name FROM buyers RIGHT JOIN products ON
buyers.pid=products.id;
+------------+----------+--------------+
| buyer_name | quantity | product_name |
+------------+----------+--------------+
| Steve | 2 | Shoes |
| John | 1 | Laptop |
| Larry | 1 | Monitor |
| Michael | 5 | Monitor |
| NULL | NULL | DVD |
+------------+----------+--------------+
5 rows in set (0.00 sec)
LEFT조인과 결과는 같지만 어디를 기준으로 조인할 지가 다를 뿐이다.
잼나네 ㅋㅋ
이쪽 클럽 에이스랑 저쪽 클럽 에이스랑 붙으면 누가 이김 ㅋㅋ
뭐이런거 ㅋㅋ
right 조인은
이쪽 클럽 에이스랑 저쪽 클럽 에이스는 둘다 이쁘다 머이런건가 ㅋㅋ
MySql Left Right 조인Projects 와 Buyers 2개의 테이블을 생성한다.
mysql> SELECT * FROM products;
+----+--------------+--------------+
| id | product_name | manufacturer |
+----+--------------+--------------+
| 1 | Shoes | Company1 |
| 2 | Laptop | Company2 |
| 3 | Monitor | Company3 |
| 4 | DVD | Company4 |
+----+--------------+--------------+
4 rows in set (0.00 sec)
Table buyers:
mysql> SELECT * FROM buyers;
+----+------+------------+----------+
| id | pid | buyer_name | quantity |
+----+------+------------+----------+
| 1 | 1 | Steve | 2 |
| 2 | 2 | John | 1 |
| 3 | 3 | Larry | 1 |
| 4 | 3 | Michael | 5 |
| 5 | NULL | Steven | NULL |
+----+------+------------+----------+
5 rows in set (0.00 sec)
Left Join
mysql> SELECT buyer_name, quantity, product_name FROM buyers LEFT JOIN products ON
buyers.pid=products.id;
+------------+----------+--------------+
| buyer_name | quantity | product_name |
+------------+----------+--------------+
| Steve | 2 | Shoes |
| John | 1 | Laptop |
| Larry | 1 | Monitor |
| Michael | 5 | Monitor |
| Steven | NULL | NULL |
+------------+----------+--------------+
5 rows in set (0.00 sec)
* 가장많이 사용하는 조인
* 조인하는 쪽의 데이터가 존재하지 않더라도 Null로 조인한다.
Right Join
mysql> SELECT buyer_name, quantity, product_name FROM buyers RIGHT JOIN products ON
buyers.pid=products.id;
+------------+----------+--------------+
| buyer_name | quantity | product_name |
+------------+----------+--------------+
| Steve | 2 | Shoes |
| John | 1 | Laptop |
| Larry | 1 | Monitor |
| Michael | 5 | Monitor |
| NULL | NULL | DVD |
+------------+----------+--------------+
5 rows in set (0.00 sec)
LEFT조인과 결과는 같지만 어디를 기준으로 조인할 지가 다를 뿐이다.
잼나네 ㅋㅋ
이쪽 클럽 에이스랑 저쪽 클럽 에이스랑 붙으면 누가 이김 ㅋㅋ
뭐이런거 ㅋㅋ
right 조인은
이쪽 클럽 에이스랑 저쪽 클럽 에이스는 둘다 이쁘다 머이런건가 ㅋㅋ
추천
0
0
댓글 2개
좋은 정보 감사합니다.
좋아요~