Join Table

I have got an interview question as below for 2 tables and give the results

Table A
1
0
NULL

Table B
1
1
NULL

QUESTION ?

What is the result Left Join
What is the result Left Join
What is the result Inner Join

Can i write as
Select * from TableA where Col = NULL

I am not sure of your data representation and questions since you have two questions for "LEFT".

Here is the syntax and diagram for the (LEFT, RIGHT and INNER) which is the top three illustrations

Diagram

Assuming Table A is the first table and Table B is the second table for Left Outer Join:

SELECT * FROM TableA
LEFT OUTER JOIN TableB ON TableB.ID = TableA.ID

Basically, Left Join is get everything from the first table (Table A) and any matches from the second table (Table B). Right Join is get everything from the second table (Table B) and any matches from the first table. Inner Join is to return only matches.

Usually, Left Join and Inner Join are used more frequently than Right Join.

1 Like

The result of this:
SELECT * FROM dbo.[Table A] AS A LEFT JOIN dbo.[Table B] AS B ON B.col1 = A.col1
is this:
col1[A] col1[B]
1 1
1 1
0 NULL
NULL NULL

of this:
SELECT * FROM dbo.[Table B] AS B LEFT JOIN dbo.[Table A] AS A ON B.col1 = A.col1
is this:
col1[B] col1[A]
1 1
1 1
NULL NULL

of this:
SELECT * FROM dbo.[Table A] AS A INNER JOIN dbo.[Table B] AS B ON B.col1 = A.col1
is this:
col1[A] col1[B]
1 1
1 1