Jump to content

JOIN multiple tables?


Boo-urns

Recommended Posts

What i'm trying to do is join multiple tables together (3 tables) I can get it to work fine if a user has data in all 3 but how would you go about it if there was only 1 table or 2 tables with the data?

 

"SELECT * FROM magazine_reviews LEFT JOIN (book_reviews LEFT JOIN poem_reviews ON book_reviews.userID = poem_reviews.userID) ON magazine_reviews.userID = book_reviews.userID OR magazine_reviews.userID = poem_reviews.userID WHERE beer_reviews.userID='$id'

 

Any ideas? This will work fine if there is data in all 3 or even if its just in magazine_reviews.

 

Thanks for your help

Link to comment
Share on other sites

"SELECT * FROM magazine_reviews LEFT JOIN (book_reviews LEFT JOIN poem_reviews ON book_reviews.userID = poem_reviews.userID) ON magazine_reviews.userID = book_reviews.userID OR magazine_reviews.userID = poem_reviews.userID WHERE beer_reviews.userID='$id'"

 

 

Hrmmmm didn't notice that you were already using LEFT JOIN.  To be honest, I read the text part of your post and didn't see the query ;p.

 

 

 

It looks like maybe you should be using a UNION.  How are you using the extracted data?

 

 

 

So uhmmmm....  What exactly do you want the results from the query to look like?

 

 

You basically want to pull everything from every table for a specific id?  Sounds like you need UNION to me.  If not, I can try to help figure out the joining.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.