Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple join Query

Status
Not open for further replies.

atiqraza

Programmer
Jan 9, 2007
24
US
Could anyone tell me what i am doing wrong here,
I want to do join three tables together,
I have one master table and i am performing a left outer join on it with two tables.

select * from custmast a left outer join chainmlrc b, chainbanner c on
a.country = b.country and
a.can_prim_chain_code = b.[chain ID] and
a.can_prim_chain_code = c.[chain ID] and
a.can_prim_region_code =c.[banner ID]

Is this possible or do i have to create a view for the first join and then join it with the second table.
 
Your syntax is wrong. It should be like this...

Code:
select * 
from   custmast a 
       left outer join chainmlrc b
         a.country = b.country and 
         a.can_prim_chain_code = b.[chain ID]
       left join chainbanner c on 
         a.can_prim_chain_code = c.[chain ID] and
         a.can_prim_region_code =c.[banner ID]

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
You have to do 2 separate joins on these tables it would look like this:

Code:
select  * from custmast a 
left outer join chainmlrc b
   on a.can_prim_chain_code = b.[chain ID] and a.country = b.country 
left outer join chainbanner c on 
   b.[chain_id] = c.[chain ID] and a.can_prim_region_code = c.[banner ID]

 
Hey thnx it worked!!
I knew i was doing something stupid....
 
>> I knew i was doing something stupid....

Actually, I think you just did something smart. You learned the proper way to join tables. [smile]

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top