Left Join Vs Right Join

  • Hi All,

    What is difference between Left Join Vs Right join since if i swap the table position, i get the same result.

    Thanks,

    Prashant N

  • Left outer join returns all records from left table, at same time, it brings all matching rows from right table for the given predicate and NULL appears in right side when no matching row exists.

    Right outer join returns all records from right table, at the same time, it brings all matching rows from left table for the given predicate, and NULL appears in left side when no matching row exists.

    there are lot of example, just Google it.

    [font="Calibri"]Raj[/font]
  • Maybe this will give you a better perspective on how the different types of joins work.

    DECLARE @Table1 TABLE( MyID int);

    INSERT INTO @Table1 VALUES(1),(2),(3),(4)

    DECLARE @Table2 TABLE( MyID int);

    INSERT INTO @Table2 VALUES(4),(5),(6),(7)

    SELECT *

    FROM @Table1 t1

    --INNER

    JOIN @Table2 t2 ON t1.MyID = t2.MyID

    SELECT *

    FROM @Table1 t1

    LEFT

    JOIN @Table2 t2 ON t1.MyID = t2.MyID

    SELECT *

    FROM @Table1 t1

    RIGHT

    JOIN @Table2 t2 ON t1.MyID = t2.MyID

    SELECT *

    FROM @Table1 t1

    FULL

    JOIN @Table2 t2 ON t1.MyID = t2.MyID

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply