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
https://forums.phpfreaks.com/topic/145855-join-multiple-tables/
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
https://forums.phpfreaks.com/topic/145855-join-multiple-tables/#findComment-768882
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.