patche — 2010-10-10T14:29:29-04:00 — #1
Have a table in which I need to get two user's usernames from it. I.e.
challenge(id, challengerid, receiverid)
challengerid and receiverid are ids from the member table.
how do I get both the challengerid's username aswell as the receiverid's username with the same query?
Any help would be awesome!
patche — 2010-10-11T09:59:57-04:00 — #2
guido2004 — 2010-10-10T14:35:06-04:00 — #3
Just like you say in the title... join the same table twice, using aliasses to give them a unique name in the query:
INNER JOIN members AS m1
INNER JOIN members AS m2
r937 — 2010-10-10T16:02:05-04:00 — #4
i don't like the generic aliases when there are much nicer ones available
, challenger.username AS challenger
, receiver.username AS receiver
JOIN member AS challenger
ON challenger.id = challenge.challengerid
JOIN member AS receiver
ON receiver.id = challenge.receiverid
i like this better than m1 and m2