Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 which is left or right table? ..join

Author  Topic 

Gekko
Yak Posting Veteran

63 Posts

Posted - 2012-01-31 : 12:48:26
hallo

when I write query left outer join or (right outer join)
how I know which table is the left or right ?
how to differentiate left table, right table?

thanks

skybvi
Posting Yak Master

193 Posts

Posted - 2012-01-31 : 12:51:53
its in the order of your writng

for ex ..
select * from A
left JOIN B
on A. =B.

Here A is left table
B is right table.

Regards,
Sushant
DBA
Virgin Islands(U.K)
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-01-31 : 12:51:58
don't use right join

SELECT LeftTable LEFT JOIN RightTable ON...

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

Gekko
Yak Posting Veteran

63 Posts

Posted - 2012-01-31 : 13:15:26
quote:
Originally posted by skybvi

its in the order of your writng

for ex ..
select * from A
left JOIN B
on A. =B.

Here A is left table
B is right table.



I understand when I write
x x x
left outer join
on TabA=TabB

it means TabA is left and TabB is right
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2012-01-31 : 13:16:58
quote:
Originally posted by Gekko

hallo

when I write query left outer join or (right outer join)
how I know which table is the left or right ?
how to differentiate left table, right table?

thanks

Sql reads from left to right. So, the table preceeding a join is always the LEFT and the table following the join is the RIGHT. But, since you are asking about LEFT and RIGHT joins, are you asking which table is the Dominant and Subordinate?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-01-31 : 13:17:19
quote:
Originally posted by Gekko

hallo

when I write query left outer join or (right outer join)
how I know which table is the left or right ?
how to differentiate left table, right table?

thanks


the side determines side in which tables come in query with respect to join. so tables on left side of join are left tables and on right are right tables

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-01-31 : 13:26:30
quote:
Originally posted by Gekko

quote:
Originally posted by skybvi

its in the order of your writng

for ex ..
select * from A
left JOIN B
on A. =B.

Here A is left table
B is right table.



I understand when I write
x x x
left outer join
on TabA=TabB

it means TabA is left and TabB is right


not exactly
its like

xxx x
left outer join yyy y
on y.somecolumn=x.somecolumn


here xxx is left table,yyy is right table
x and y are short names (aliases) for the tables for easy reference

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

jeffw8713
Aged Yak Warrior

819 Posts

Posted - 2012-01-31 : 14:31:01
quote:
I understand when I write
x x x
left outer join
on TabA=TabB

it means TabA is left and TabB is right



The order of the predicates in the join do not determine this.

SELECT ... FROM tableA a LEFT JOIN tableB b ON a.key = b.key
SELECT ... FROM tableA a LEFT JOIN tableB b ON b.key = a.key

Both of the above are the same...

SELECT ... FROM tableA a LEFT JOIN tableB b ON a.key = b.key
SELECT ... FROM tableB b LEFT JOIN tableA a ON b.key = a.key

Both of the above are not the same - regardless of the order of the predicates in the ON clause.

Jeff
Go to Top of Page

Gekko
Yak Posting Veteran

63 Posts

Posted - 2012-01-31 : 14:43:08
thanks for definition, constructions
Go to Top of Page
   

- Advertisement -