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!

Help with a join

Status
Not open for further replies.

Foamcow

Programmer
Nov 14, 2002
6,092
GB
Can someone help me with this pretty simple query?

Some of you may know that I just can't get the hang of joins - they require masses of mental effort on my part and I'm pretty burned out at the moment so this is just not happening for me.

Here's the gist of what I am trying to do.

I have 3 tables

pages - contains main info for a page on the site
suppContent - contains extra info that may appear on pages within the site
pageToSuppContentId - contains info to map suppContent to Pages. It maps pageId to suppContentId

I know the pageId and I need to get the correct suppContent Row based on the pageId mapped against it in the suppContentToPage table

So I look up the suppContentId in the pageToSuppContentId table
Code:
	SELECT ptsc.suppContentId FROM pageToSuppContentId ptsc WHERE ptsc.pageId = <page_id>
I can then use this suppContentId to lookup the data from the suppContent table
Code:
	SELECT sc.* FROM  suppContent sc WHERE sc.id = <suppContentId>
How can I combine this into a single query?

<honk>*:O)</honk>

Earl & Thompson Marketing - Marketing Agency Services in Gloucestershire
 
Foamcow, welcome to the dark side. How about something like:
Code:
SELECT sc.* FROM  suppContent sc 
INNER JOIN  pageToSuppContentId ptsc ON sc.id = ptsc.suppContentId
WHERE ptsc.pageId = <page_id>
depend

Greg
"Personally, I am always ready to learn, although I do not always like being taught." - Winston Churchill
 
Thankyou lespaul.
Actually I've read that before. I'm afraid I have an appaling mental block when it comes to joins. They just don't 'click'.

But, I'll give it another read because its something I really need to get a handle on.

Thanks again

<honk>*:O)</honk>

Earl & Thompson Marketing - Marketing Agency Services in Gloucestershire
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top