SQL Interview Prep 2: Is it possible for LEFT JOIN and FULL OUTER JOIN to produce the same results? Why or why not?

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

IDName
1Karma
2Dolma
3Tashi

Table 2

IDBooks
1Start With Why by Simon Sinek
1Sherlock Holmes by Sir Arthur Conan Doyle
25 People You Meet In Heaven by Mitch Albom
4Have a Little Faith by Mitch Albom

Left Join of Table 1 and Table 2

IDNameIDBooks
1Karma1Start With Why by Simon Sinek
1Karma1Sherlock Holmes by Sir Arthur Conan Doyle
2Dolma25 People You Meet In Heaven by Mitch Albom
3TashiNullNull

Full Outer Join of Table 1 and Table 2

IDNameIDBooks
1Karma1Start With Why by Simon Sinek
1Karma1Sherlock Holmes by Sir Arthur Conan Doyle
2Dolma25 People You Meet In Heaven by Mitch Albom
3TashiNullNull
NullNull4Have 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

IDName
1Karma
2Dolma
3Tashi

Table 2

IDBooks
1Start With Why by Simon Sinek
1Sherlock Holmes by Sir Arthur Conan Doyle
25 People You Meet In Heaven by Mitch Albom
3The Magical Strings of Frankie Presto by Mitch Albom

LEFT JOIN

IDNameIDBooks
1Karma1Start With Why by Simon Sinek
1Karma1Sherlock Holmes by Sir Arthur Conan Doyle
2Dolma25 People You Meet In Heaven by Mitch Albom
3Tashi3The Magical Strings of Frankie Presto by Mitch Albom

FULL OUTER JOIN

IDNameIDBooks
1Karma1Start With Why by Simon Sinek
1Karma1Sherlock Holmes by Sir Arthur Conan Doyle
2Dolma25 People You Meet In Heaven by Mitch Albom
3Tashi3The Magical Strings of Frankie Presto by Mitch Albom

Leave a comment