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
 General SQL Server Forums
 New to SQL Server Programming
 Join Question

Author  Topic 

Grifter
Constraint Violating Yak Guru

274 Posts

Posted - 2011-11-02 : 07:21:53
Hi

When joining two tables and you want to see all data from say tableA that matches data in TableB but also want to see data that does not match from Table A; is the join then:

select *
from table A left outer join Table B on A.ID = B.ID

When you say 'LEFT OUTER JOIN' are you referring to the table in the left of the join statement (table A left outer join Table B) or the join condition (A.ID = B.ID) because you could easily say (B.ID = A.ID) then the left outer join would be on the other table.

Thanks for clarifying this

G

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-02 : 07:24:38
nope. its table that we're refering to
A LEFT JOIN B means A is base table (whose all rows are returned)
B LEFT JOIN A means other way round

similarly

A RIGHT JOIN B means B is base table (table on right side wose all rows are retrieved)

the condition specified would be same whether you specify it as A.ID = B.ID or B.ID = A.ID

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

Go to Top of Page

Grifter
Constraint Violating Yak Guru

274 Posts

Posted - 2011-11-02 : 07:46:35
Hi

Ok so where the reference to the table in the actual join condition does not matter....A.ID = B.ID

G
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-02 : 07:50:19
quote:
Originally posted by Grifter

Hi

Ok so where the reference to the table in the actual join condition does not matter....A.ID = B.ID

G


yes...thats right

you can check it yourself by creating two sample tables and doing left join between them

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

Go to Top of Page

jassi.singh
Posting Yak Master

122 Posts

Posted - 2011-11-03 : 04:38:10
Hi,

Also check this out : http://www.mssqltips.com/sqlservertip/1667/sql-server-join-example/

Please mark answer as accepted if it helped you.

Thanks,
Jassi Singh
Go to Top of Page
   

- Advertisement -