365 Days of Daily Coding: Day 110
Is it possible for LEFT JOIN and FULL OUTER JOIN to produce the same results? Why or why not?
LEFT JOIN: Returns all the records that are common between Table 1 and Table 2 as well as the non-matching records from Table 1.
FULL OUTER JOIN: Returns all the records that are common between Table 1 and Table 2 as well as the non-matching records from Table 1 and Table 2.
Table 1
| ID | Name |
| 1 | Karma |
| 2 | Dolma |
| 3 | Tashi |
Table 2
| ID | Books |
| 1 | Start With Why by Simon Sinek |
| 1 | Sherlock Holmes by Sir Arthur Conan Doyle |
| 2 | 5 People You Meet In Heaven by Mitch Albom |
| 4 | Have a Little Faith by Mitch Albom |
Left Join of Table 1 and Table 2
| ID | Name | ID | Books |
| 1 | Karma | 1 | Start With Why by Simon Sinek |
| 1 | Karma | 1 | Sherlock Holmes by Sir Arthur Conan Doyle |
| 2 | Dolma | 2 | 5 People You Meet In Heaven by Mitch Albom |
| 3 | Tashi | Null | Null |
Full Outer Join of Table 1 and Table 2
| ID | Name | ID | Books |
| 1 | Karma | 1 | Start With Why by Simon Sinek |
| 1 | Karma | 1 | Sherlock Holmes by Sir Arthur Conan Doyle |
| 2 | Dolma | 2 | 5 People You Meet In Heaven by Mitch Albom |
| 3 | Tashi | Null | Null |
| Null | Null | 4 | Have a Little Faith by Mitch Albom |
To answer the question, yes I do think it is possible for LEFT JOIN and LEFT OUTER JOIN to produce the same results. This can happen when every record in Table 1 has a matching record in Table 2.
Table 1
| ID | Name |
| 1 | Karma |
| 2 | Dolma |
| 3 | Tashi |
Table 2
| ID | Books |
| 1 | Start With Why by Simon Sinek |
| 1 | Sherlock Holmes by Sir Arthur Conan Doyle |
| 2 | 5 People You Meet In Heaven by Mitch Albom |
| 3 | The Magical Strings of Frankie Presto by Mitch Albom |
LEFT JOIN
| ID | Name | ID | Books |
| 1 | Karma | 1 | Start With Why by Simon Sinek |
| 1 | Karma | 1 | Sherlock Holmes by Sir Arthur Conan Doyle |
| 2 | Dolma | 2 | 5 People You Meet In Heaven by Mitch Albom |
| 3 | Tashi | 3 | The Magical Strings of Frankie Presto by Mitch Albom |
FULL OUTER JOIN
| ID | Name | ID | Books |
| 1 | Karma | 1 | Start With Why by Simon Sinek |
| 1 | Karma | 1 | Sherlock Holmes by Sir Arthur Conan Doyle |
| 2 | Dolma | 2 | 5 People You Meet In Heaven by Mitch Albom |
| 3 | Tashi | 3 | The Magical Strings of Frankie Presto by Mitch Albom |

Leave a comment