SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Where is Left table in Left Join ???


Where is Left table in Left Join ???

Author
Message
mario17
mario17
SSC-Addicted
SSC-Addicted (488 reputation)SSC-Addicted (488 reputation)SSC-Addicted (488 reputation)SSC-Addicted (488 reputation)SSC-Addicted (488 reputation)SSC-Addicted (488 reputation)SSC-Addicted (488 reputation)SSC-Addicted (488 reputation)

Group: General Forum Members
Points: 488 Visits: 683
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
ALZDBA
ALZDBA
SSChampion
SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)

Group: General Forum Members
Points: 12634 Visits: 8930
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


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


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


press F1 for solution, press shift+F1 for urgent solution :-D


Need a bit of Powershell? How about this

Who am I ? Sometimes this is me Alien but most of the time this is me Hehe
mario17
mario17
SSC-Addicted
SSC-Addicted (488 reputation)SSC-Addicted (488 reputation)SSC-Addicted (488 reputation)SSC-Addicted (488 reputation)SSC-Addicted (488 reputation)SSC-Addicted (488 reputation)SSC-Addicted (488 reputation)SSC-Addicted (488 reputation)

Group: General Forum Members
Points: 488 Visits: 683
ALZDBA
Hi, Alzdba
Bit hard to get your answer so it's left from the JOIN or left from "="


Mario
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)

Group: General Forum Members
Points: 89559 Visits: 41144
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.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
ALZDBA
ALZDBA
SSChampion
SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)

Group: General Forum Members
Points: 12634 Visits: 8930
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


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


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


press F1 for solution, press shift+F1 for urgent solution :-D


Need a bit of Powershell? How about this

Who am I ? Sometimes this is me Alien but most of the time this is me Hehe
MMartin1
MMartin1
SSCrazy
SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)

Group: General Forum Members
Points: 2863 Visits: 2031
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.

----------------------------------------------------
How to post forum questions to get the best help
Loundy
Loundy
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1844 Visits: 1190
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.....


There's no kill switch on awesome!
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search