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
https://forums.phpfreaks.com/topic/92751-doubble-join/
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
https://forums.phpfreaks.com/topic/92751-doubble-join/#findComment-475199
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.