homepage Welcome to WebmasterWorld Guest from 54.204.215.209
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld

Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderators: physics

Databases Forum

    
JOIN two tables deep? Outer join?
Join a table through an already joined table?
JAB Creations




msg:4115948
 7:52 pm on Apr 14, 2010 (gmt 0)

The page the query is called on is when viewing a forum thread. In the query I select from the forum_posts table and join the forum_threads table. I'm trying to figure out if I can select data from the forum_forums table to fetch the post/reply permissions.

Table / Unique ID (via Alias)
forum_forums = ff.id
forum_threads = ft.id
forum_posts = fp.id

This is what my current query looks like slimmed down...
SELECT *
FROM forum_posts AS fp
INNER JOIN forum_threads AS ft ON (fp.id_thread=ft.id_thread)


I was reading about outer joins...not sure if it's necessary or not. I'm not exactly sure spatially speaking of how outer and inner joins relate exactly.

So is there a way to join the forum_forums table the already joined forum_threads table?

- John

 

LifeinAsia




msg:4115982
 9:03 pm on Apr 14, 2010 (gmt 0)

So is there a way to join the forum_forums table the already joined forum_threads table?

Yes. It's just a matter of joining them on a common field, as you've already done with the INNER JOIN between forum_posts and forum_threads.

Assuming you have a field forum_threads.id_forum, the following should work:
SELECT *
FROM forum_threads AS fp
INNER JOIN forum_threads AS ft ON fp.id_thread=ft.id_thread INNER JOIN forum_forums AS ff ON ft.id_forum=ff.id_forum

JAB Creations




msg:4116536
 8:00 pm on Apr 15, 2010 (gmt 0)

Got it working and I initially had something mixed up, thanks!

- John

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved