Jump to content

Doubble join?


ari_aaron

Recommended Posts

I have a user table like this:

UID    | Username
2         theuser
5         ari_aaron
3         me
4         blah

 

and another table like this:

Giver    | Receiver   | Comments
2          5                 hi!
4          3                test
2          4                 ...

I am using this SQL:

SELECT users.username AS give_name, tans.* FROM users INNER JOIN trans ON trans.receiver=users.UID

In order to show usernames instead of UIDs.

 

 

How can I get this to work for both giver and receiver?

Link to comment
Share on other sites

Hi,

 

This works - but maybe not the tidiest!

 

SELECT
use_give.Username AS Giver_Name,
users.Username AS Receiver_Name,
trans.Comments
FROM
trans
Inner Join users ON trans.Receiver = users.uid
Inner Join users AS use_give ON trans.Giver = use_give.uid

 

HTH Dave

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.