Where is Left table in Left Join ???

  • Hi all, I did my home work but just want to confirm where is that Left table on Left SQL :

    a. Very Firs mentioned in Select

    b. on the Left side of equation in ON statement.

    Is this the same:

    Select T1.C1, T2.C2

    From T1 Left join T2

    on T1.C1 =. T2.C2

    vs.

    Select T1.C1, T2.C2

    From T1 Left join T2

    on T2.C2 = T1.C1. ------ note t2 first here

    What if I do lef5 join on tables which are not on main select? In this case order could be determined from "=" line ?

    Tx

    Mario

  • well, consider it as if you were to write the from part in a (long) single line

    In English, we read it from left to right, correct ?

    Hence a left outer join will keep all objects mentioned "previously" in the from line.

    It doesn't take the on-clause in account to determine what is left/right

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

  • ALZDBA

    Hi, Alzdba

    Bit hard to get your answer so it's left from the JOIN or left from "="

    Mario

  • mario17 (6/23/2013)


    ALZDBA

    Hi, Alzdba

    Bit hard to get your answer so it's left from the JOIN or left from "="

    Mario

    It would be to the "left" (before) of the word "JOIN". It makes no difference what order they are in around the "=" sign so do what you will there for the easiest understanding.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • unlike the old syntax ( not using the keyword JOIN ) the placement of the on-clause predicates don't play a role in determining the left part of your left join.

    left join right

    from table1 left join table2 would consider table1 as the left part.

    from tableB left join tableA would consider tableB as the left part.

    from table1 right join table2 would consider table2 as the right part.

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

  • I hope I dont confuse you here :

    Select T1.C1, T2.C2

    From T1 Left join T2

    on T1.C1 =. T2.C2

    is equivalent to

    Select T1.C1, T2.C2

    From T2 Right join T1

    on T1.C1 =. T2.C2

    The understanding, important to keep in mind, is that you want all data from table t1 regardless of if it has a join to t2. The same is not true of t2, you only return those that have a join to t1.

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

  • It's the table left of the JOIN operator for a left join and right of the JOIN operator in a right join.

    SELECT *

    FROM Table1 -- <-- Left Table (data is preserved in this table)

    LEFT JOIN Table2

    ON Table1.column = Table2.column

    Where.....

    SELECT *

    FROM Table1

    RIGHT JOIN Table2 -- <-- Right Table (data is preserved in this table)

    ON Table1.column = Table2.column

    Where.....

    [font="Times New Roman"]There's no kill switch on awesome![/font]

Viewing 7 posts - 1 through 6 (of 6 total)

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