The PL/SQL LEFT JOIN return all rows from the left table, although there are no matches in the right table.
Phones table
PHONE_ID |
PHONE_NAME |
BRAND_ID |
1 |
Galaxy Note Edge |
1 |
2 |
N910 Galaxy Note 4 |
1 |
3 |
Galaxy S5 Duos 4G |
1 |
4 |
iPhone 5S |
2 |
5 |
iPhone 6 Plus |
2 |
6 |
930 Lumia |
3 |
7 |
830 Lumia |
3 |
Phone_brands table
BRAND_ID |
NAME |
1 |
Samsung |
2 |
Apple |
3 |
Nokia |
4 |
HTC |
5 |
BlackBerry |
Left Join example
SELECT b.brand_id, b.name as brand, p.phone_name
FROM phone_brands b LEFT JOIN phones p
ON b.brand_id=p.brand_id
ORDER BY b.brand_id;
Output
BRAND_ID |
BRAND |
PHONE_NAME |
1 |
Samsung |
Galaxy Note Edge |
1 |
Samsung |
N910 Galaxy Note 4 |
1 |
Samsung |
Galaxy S5 Duos 4G |
2 |
Apple |
iPhone 5S |
2 |
Apple |
iPhone 6 Plus |
3 |
Nokia |
930 Lumia |
3 |
Nokia |
830 Lumia |
4 |
HTC |
(null) |
5 |
BlackBerry |
(null) |