Boo-urns Posted February 19, 2009 Share Posted February 19, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/145855-join-multiple-tables/ Share on other sites More sharing options...
mjahkoh Posted February 21, 2009 Share Posted February 21, 2009 Don waste time linking tables manually. use navicat Quote Link to comment https://forums.phpfreaks.com/topic/145855-join-multiple-tables/#findComment-767652 Share on other sites More sharing options...
Boo-urns Posted February 22, 2009 Author Share Posted February 22, 2009 I'm joining the tables for a query I need to pull for the users. (I'm not sure why you suggest to use navicat for that.) I have navicat but just use it to browse search the db. Quote Link to comment https://forums.phpfreaks.com/topic/145855-join-multiple-tables/#findComment-768099 Share on other sites More sharing options...
corbin Posted February 22, 2009 Share Posted February 22, 2009 Boo-urns, you should probably use a LEFT JOIN or maybe a RIGHT JOIN. mjahkoh, that's horrible advice. Quote Link to comment https://forums.phpfreaks.com/topic/145855-join-multiple-tables/#findComment-768258 Share on other sites More sharing options...
Boo-urns Posted February 22, 2009 Author Share Posted February 22, 2009 Any idea where I've gone wrong w/ my LEFT JOIN? Or would you suggest multiple queries? Quote Link to comment https://forums.phpfreaks.com/topic/145855-join-multiple-tables/#findComment-768285 Share on other sites More sharing options...
corbin Posted February 23, 2009 Share Posted February 23, 2009 "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. Quote Link to comment https://forums.phpfreaks.com/topic/145855-join-multiple-tables/#findComment-768882 Share on other sites More sharing options...
Boo-urns Posted February 23, 2009 Author Share Posted February 23, 2009 Alright thanks for the tip i'll look into UNION Quote Link to comment https://forums.phpfreaks.com/topic/145855-join-multiple-tables/#findComment-768900 Share on other sites More sharing options...
Boo-urns Posted February 24, 2009 Author Share Posted February 24, 2009 Hmm UNION didn't cooperate for me. The way I got it to work is I checked if their is any data in the 3 tables had a switch statement to create the queries correlating to it. Might not be the best way but it's working. Quote Link to comment https://forums.phpfreaks.com/topic/145855-join-multiple-tables/#findComment-770126 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.