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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Anyone with complex JOIN experience 2

Status
Not open for further replies.

ton12

Programmer
Mar 9, 2005
58
GB
Hi,

I have four tables Tab1,Tab2,Tab3 and Tab4
and I need to create a fifth table using values
from Tab1 and Tab4 but there are no common columns
between Tab1 and Tab4. However, there are common
columns beween.

Tab1 and Tab2
Tab2 and Tab3
Tab3 and Tab4

Table Columns
---- -------
Tab1 b_number, S_NUMBER
Tab2 S_NUMBER, ac_id
Tab3 ac_id, r_id
Tab4 r_id, s_des

I need to write 'b_number', 'S_NUMBER' and 's_des' to a
new table.

Any help would be appreciated.

Thanks.

Ton



 
link the joins

Select b_number,s_des
from Tab1
inner join Tab2
on tab1.S_NUMBER=tab2.S_NUMBER
inner join tab3
on tab2.ac_id=tab3.ac_id
inner join tab4
tab3.r_id=tab4.r_id


 
hi Ton,

i maybe wrong but i think you can just do the following...

Code:
select
1.b_number,
1.s_number,
4.s_des
from tab1 1
join tab2 2 on 2.s_number = 1.s_number
join tab3 3 on 3.ac_id = 2.ac_id
join tab4 4 on 4.r_id = 3.r_id

as i say i think that is right?
apologies if not!

Dan.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top