Union
右外部結合はベン図の に似ていますよね?
つまり、 のすべての行と一致する行A right outer Join B
をすべて取得する必要があります。
何らかの理由で、次のことと混同しています:
Assume table : B
A
Orders
mysql> select * from orders;
+------------+------------+---------+----------+---------+
| orderedon | name | partnum | quantity | remarks |
+------------+------------+---------+----------+---------+
| 1996-05-19 | TRUE-WHEEL | 76 | 3 | PAID |
| 1996-09-02 | TRUE-WHEEL | 10 | 1 | PAID |
| 1996-06-30 | TRUE-WHEEL | 42 | 8 | PAID |
| 1996-06-30 | BIKE SPEC | 54 | 10 | PAID |
| 1996-05-30 | BIKE SPEC | 23 | 8 | PAID |
| 1996-01-17 | BIKE SPEC | 76 | 11 | PAID |
| 1996-01-17 | LE SHOPPE | 76 | 5 | PAID |
| 1996-06-01 | LE SHOPPE | 10 | 3 | PAID |
| 1996-06-01 | AAA BIKE | 10 | 1 | PAID |
| 1996-07-01 | AAA BIKE | 76 | 4 | PAID |
| 1996-07-01 | AAA BIKE | 46 | 14 | PAID |
| 1996-07-11 | JACKS BIKE | 76 | 14 | PAID |
| 1996-05-15 | TRUE-WHEEL | 23 | 6 | PAID |
| 1996-05-30 | BIKE SPEC | 20 | 2 | PAID |
+------------+------------+---------+----------+---------+
14 rows in set (0.00 sec)
とテーブルPart
:
mysql> select * from part;
+---------+---------------+---------+
| partnum | description | price |
+---------+---------------+---------+
| 54 | PEDALS | 54.25 |
| 42 | SEATS | 24.50 |
| 46 | TIRES | 15.25 |
| 23 | MOUNTAIN BIKE | 350.45 |
| 76 | ROAD BIKE | 530.00 |
| 10 | TANDEM | 1200.00 |
+---------+---------------+---------+
6 rows in set (0.00 sec)
次のクエリを期待して
select p.partnum p_partnum,p.description p_desc,p.price p_price,o.name o_name,o.partnum o_partnum from part p right outer join orders o on o.partnum=54;
いましOrders
た。
しかし、私はこれを取得します: part
partnum=54
mysql> select p.partnum p_partnum,p.description p_desc,p.price p_price,o.name o_name,o.partnum o_partnum from part p right outer join orders o on o.partnum=54;
+-----------+---------------+---------+------------+-----------+
| p_partnum | p_desc | p_price | o_name | o_partnum |
+-----------+---------------+---------+------------+-----------+
| NULL | NULL | NULL | TRUE-WHEEL | 76 |
| NULL | NULL | NULL | TRUE-WHEEL | 10 |
| NULL | NULL | NULL | TRUE-WHEEL | 42 |
| 54 | PEDALS | 54.25 | BIKE SPEC | 54 |
| 42 | SEATS | 24.50 | BIKE SPEC | 54 |
| 46 | TIRES | 15.25 | BIKE SPEC | 54 |
| 23 | MOUNTAIN BIKE | 350.45 | BIKE SPEC | 54 |
| 76 | ROAD BIKE | 530.00 | BIKE SPEC | 54 |
| 10 | TANDEM | 1200.00 | BIKE SPEC | 54 |
| NULL | NULL | NULL | BIKE SPEC | 23 |
| NULL | NULL | NULL | BIKE SPEC | 76 |
| NULL | NULL | NULL | LE SHOPPE | 76 |
| NULL | NULL | NULL | LE SHOPPE | 10 |
| NULL | NULL | NULL | AAA BIKE | 10 |
| NULL | NULL | NULL | AAA BIKE | 76 |
| NULL | NULL | NULL | AAA BIKE | 46 |
| NULL | NULL | NULL | JACKS BIKE | 76 |
| NULL | NULL | NULL | TRUE-WHEEL | 23 |
| NULL | NULL | NULL | BIKE SPEC | 20 |
+-----------+---------------+---------+------------+-----------+
19 rows in set (0.00 sec)
余分な行が表示されるのはなぜですか? Order
withpartnum=54
の行を `part のすべての行に結合するのはなぜですか?