guyfromfl Posted June 19, 2008 Share Posted June 19, 2008 I have two tables - questions, and people questions: +---+-----------+-----------+ | id | condition1 | condition2 | +---+-----------+-----------+ | 1 | 1 | 2 | | 2 | 4 | 3 | | 3 | 2 | 4 | +---+-----------+-----------+ people: +----+-----------+ | id | pic | +----+-----------+ | 1 | you | | 2 | me | | 3 | dog | | 4 | cat | +----+-----------+ so from a list genereated by php, i want to see what 3 is, so that would reference id 3 from table questions, then go see 2 and 4 in people. me, and cat.. I came up with this but it tells me questions.condition1 aren't known columns SELECT people.pic FROM people WHERE people.id=questions.condition1 AND questions.id=3; any help!? Thanks Quote Link to comment Share on other sites More sharing options...
rhodesa Posted June 19, 2008 Share Posted June 19, 2008 SELECT people.pic FROM people LEFT JOIN questions ON people.id = questions.condition1 WHERE questions.id = 3 Quote Link to comment Share on other sites More sharing options...
guyfromfl Posted June 19, 2008 Author Share Posted June 19, 2008 awsome VERY close! now i need to have condition2 returned too..is it possible with one query to get both? Quote Link to comment Share on other sites More sharing options...
rhodesa Posted June 19, 2008 Share Posted June 19, 2008 SELECT p.pic FROM people p LEFT JOIN questions q1 ON p.id = q1.condition1 LEFT JOIN questions q2 ON p.id = q2.condition2 WHERE q1.id = 3 OR q2.id = 3 Quote Link to comment Share on other sites More sharing options...
guyfromfl Posted June 20, 2008 Author Share Posted June 20, 2008 thats it! You're a machine man Thanks for the help!!! Quote Link to comment 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.