Welcome to WebmasterWorld Guest from 107.20.110.201

Forum Moderators: open

Message Too Old, No Replies

JOIN two tables deep? Outer join?

Join a table through an already joined table?

     

JAB Creations

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

WebmasterWorld Senior Member jab_creations is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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

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

WebmasterWorld Administrator lifeinasia is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



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

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

WebmasterWorld Senior Member jab_creations is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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

- John
 

Featured Threads

Hot Threads This Week

Hot Threads This Month