Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (6.1k points)
recategorized by

Let’s say there are two tables Table1, Table2.

We have the following table structure for them.

create table Table1 (id int, Name varchar (10))

create table Table2 (id int, Name varchar (10))

Table1 data as follows:

    Id     Name     

    -------------

    1      A        

    2      B    

Table2 data as follows:

    Id     Name     

    -------------

    1      A        

    2      B 

    3      C

Output is same for both the mentioned statements given down below: 

select *

from Table1

  left join Table2 on Table1.id = Table2.id

select *

from Table2

  right join Table1 on Table1.id = Table2.id

Please explain the difference between left and right join in the above SQL statements.

1 Answer

0 votes
by (11.7k points)

These two queries 

Select * from Table1 left join Table2 ...

and

Select * from Table2 right join Table1 …

Are actually interchangeable. But  Table2 left join Table1 and its identical pair, Table1 right join Table2 to find out the difference. The query should give you more rows because table2 is having a row with id which is not present in Table1.

If you want to get more insights into SQL, check out this SQL Course from Intellipaat.

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...