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 Link to comment https://forums.phpfreaks.com/topic/111015-solved-tough-mysql-query-problem/ 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 Link to comment https://forums.phpfreaks.com/topic/111015-solved-tough-mysql-query-problem/#findComment-569665 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? Link to comment https://forums.phpfreaks.com/topic/111015-solved-tough-mysql-query-problem/#findComment-569674 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 Link to comment https://forums.phpfreaks.com/topic/111015-solved-tough-mysql-query-problem/#findComment-569713 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!!! Link to comment https://forums.phpfreaks.com/topic/111015-solved-tough-mysql-query-problem/#findComment-569717 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.