thepip3r Posted January 20, 2009 Share Posted January 20, 2009 SELECT q.quote, q.qid, qp.paraphrase, s.*, u.username FROM quotes q LEFT JOIN quotes_paraphrases qp ON ( q.qid=qp.quote_id ) LEFT JOIN sources s ON ( q.source_id=s.sid ) LEFT JOIN users u ON ( q.user_id=u.uid ) WHERE q.enabled=1 AND q.qid=$rand my problem is that i have a numeric field in both the quotes table and the quotes_paraphrases table that are called user_id. The problem is that the person who submitted the quote and the person who submitted the paraphrase of that quote are not always the same. Is there a way to modify this SQL statement so that I can pull both the quotes.user_id=users.uid AND quotes_paraphrases.user_id=users.uid? I've tried inter-mixing an INNER join in the statement above but that gave me syntax errors (had to try), I've tried just amending the last LEFT JOIN to look like: (LEFT JOIN users u ON ( q.user_id=u.uid AND qp.user_id=u.uid) but that just adds a bunch of NULL values to the column of the result set that used to hold the user who submitted the quote where there wasn't an associated paraphrase to that particular quote. All help is greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/141532-solved-joining-dilemma-pls-assist-where-possible/ Share on other sites More sharing options...
corbin Posted January 20, 2009 Share Posted January 20, 2009 SELECT q.quote, q.qid, qp.paraphrase, s.*, qu.username AS quote_username, qpu.username AS para_username FROM quotes q LEFT JOIN quotes_paraphrases qp ON ( q.qid=qp.quote_id ) LEFT JOIN sources s ON ( q.source_id=s.sid ) LEFT JOIN users qu ON ( q.user_id=qu.uid ) LEFT JOIN users qpu ON ( q.user_id=qpu.uid ) WHERE q.enabled=1 AND q.qid=$rand Quote Link to comment https://forums.phpfreaks.com/topic/141532-solved-joining-dilemma-pls-assist-where-possible/#findComment-740862 Share on other sites More sharing options...
thepip3r Posted January 20, 2009 Author Share Posted January 20, 2009 damnit corbin... sorry for asking help on the same query two times in the same day. thanks for helping me both times -- at least you were familiar with the topic. =P thanx again. Quote Link to comment https://forums.phpfreaks.com/topic/141532-solved-joining-dilemma-pls-assist-where-possible/#findComment-740950 Share on other sites More sharing options...
corbin Posted January 20, 2009 Share Posted January 20, 2009 No problem. Quote Link to comment https://forums.phpfreaks.com/topic/141532-solved-joining-dilemma-pls-assist-where-possible/#findComment-740954 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.