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!

Multiple tables and joins

Status
Not open for further replies.

palagrim

Programmer
Apr 28, 2005
31
GB
Hi...

I'm currently working on a document system and I'm having trouble with my inner joins and stuff.

Table 1:
ID Heading_Title
1 General
2 Another Section Heading
3 Another Heading
etc...

Table 2:
HeadingID, SubHeadingID, SubHeading_Title
1 1 Sub Heading 1
1 2 Sub Heading 2
2 1 Sub Heading 3
3 1 Sub heading 4
3 2 Sub Heading 5
etc...
Table 3:
HeadingID SubHeadingID Content
1 1 <ntext>
1 2 <ntext>
2 1 <ntext>
etc...

I'm trying to match the heading_title and the sub_title to the IDs stored in table 3.

Here's what I've tried:

SELECT * from table3
inner join table2 on table2.subheadingID = table3.subheadingID
inner join table1 on table3.headingID = table1.ID

And it's throwing up multiple results for the same thing. I'm totally new to this SQL lark and it's doing my head in...

Not the most eloquent explanation in the world... If I've not been clear enough, lemme know...

Any help would be much appreciated...

Thanks.
 
When you use an Inner Join you are going to get beck the record in table one numerous times becuase that ID is in table 2 twice and table 3 numerous times as well. What kind of results are you looking for?

From what I read you are looking for this:

Select *

From Table1

Inner Join Table2 On Table2.HeadingID = Table1.HeadingID
Inner Join Table3 on Table3.HeadingID = Table2.HeadingID And Table3.SubHeadingID = Table2.SubHeadingID

 
Brilliant.

Seems to work fine!

Thank you!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top