vendredi 8 juillet 2016

Difference between left join and right join in SQL Server

I know about joins in SQL Server.

For example. there is two tables Table1, Table2.

There table structure are following.

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

If I execute both below mentioned SQL statements, both outputs will be the same

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 above sql statements.

Aucun commentaire:

Enregistrer un commentaire