Skip to content
Advertisement

I was asked the following pseudocode in a SQL interview based on joining condition. Can anyone explain what went went wrong with my approach?

[two tables-ta and tb with respective columns ]1

I was asked to put a LEFT JOIN on item id and explain what would be the possible output. I wrote a pseudocode like this-

SELECT
    table a.ITEM ID,
    table a.ITEM NAME,
    table b.ITEM ID,
    table b.ITEM NAME
from
    table a
    LEFT JOIN table b ON table a.ITEM ID = table b.ITEM ID;

I told them the output would look like this, which they told is not the right answer.

ITEM ID ITEM NAME   ITEM ID ITEM NAME
-1      X            -1     P
-1      Y            -1     Q
-1      Z            -1     R
-1      W       

Can anyone explain what would be the correct answer along with logic?

Advertisement

Answer

if the data in the screenshot was the data they gave you , all item ids are -1 which means no matter if you do inner join or outer join , its gonna be a cross join meaning you will have all combination of table1 with table 2 which will be 12 rows

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement