iamgregg Posted January 27, 2007 Share Posted January 27, 2007 I'm fine with normal join queries, but I'm having trouble with this one. I don't think I explained it well in the topic title so I'll go into more detail.Two tables:userspairsTable users has details about said users.The pairs table contains the 2 fields: user_1 and user_2, which are the respective users IDs.In one qury I want to grab the name of each user. I can do it fine for one of them but not sure how to both, e.g. how would I expand this?SELECT pairs.user_1, users.nameFROM pairs, usersWHERE pairs.user_1 = users.idI can't figure out how to do it for both? The furthest I get isSELECT pairs.user_1, pairs.user_2, users.nameFROM pairs, usersWHERE pairs.user_1 = users.id AND pairs.user_2 = users.idI know it's wrong.Anyone know?Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/35929-solved-join-a-table-more-than-once-from-a-single-table/ Share on other sites More sharing options...
Tyche Posted January 27, 2007 Share Posted January 27, 2007 You can achive this by adding the table `users` in the FROM section twice but using a different alias each timee.g.SELECT pairs.user_1, users_1.name, pairs.user_2, users_2.nameFROM pairs, users AS users_1,users AS users_2 WHERE pairs.user_1 = users_1.id AND pairs.user_2 = users_2.id Quote Link to comment https://forums.phpfreaks.com/topic/35929-solved-join-a-table-more-than-once-from-a-single-table/#findComment-170432 Share on other sites More sharing options...
iamgregg Posted January 27, 2007 Author Share Posted January 27, 2007 I just found the solution from someone else but thankyou for replying anyway.[i][b]fenway: if that's the case, post it here for all to see![/b][/i] Quote Link to comment https://forums.phpfreaks.com/topic/35929-solved-join-a-table-more-than-once-from-a-single-table/#findComment-170434 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.