Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Where is Left table in Left Join ??? Expand / Collapse
Author
Message
Posted Sunday, June 23, 2013 12:45 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Today @ 12:35 PM
Points: 196, Visits: 485
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
Post #1466505
Posted Sunday, June 23, 2013 2:06 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 11:46 PM
Points: 6,743, Visits: 8,516
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


Don't drive faster than your guardian angel can fly ...
but keeping both feet on the ground won't get you anywhere

- 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"


Need a bit of Powershell? How about this

Who am I ? Sometimes this is me but most of the time this is me
Post #1466507
Posted Sunday, June 23, 2013 12:08 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Today @ 12:35 PM
Points: 196, Visits: 485
ALZDBA
Hi, Alzdba
Bit hard to get your answer so it's left from the JOIN or left from "="


Mario
Post #1466541
Posted Sunday, June 23, 2013 3:19 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 6:59 PM
Points: 35,572, Visits: 32,165
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."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1466546
Posted Monday, June 24, 2013 12:23 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 11:46 PM
Points: 6,743, Visits: 8,516
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


Don't drive faster than your guardian angel can fly ...
but keeping both feet on the ground won't get you anywhere

- 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"


Need a bit of Powershell? How about this

Who am I ? Sometimes this is me but most of the time this is me
Post #1466591
Posted Friday, July 12, 2013 12:23 PM


SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Today @ 6:40 PM
Points: 421, Visits: 1,000
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.

Post #1473212
Posted Saturday, July 13, 2013 1:15 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Saturday, September 6, 2014 2:15 PM
Points: 1,597, Visits: 1,153
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!
Post #1473285
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse