I have 2 Tables:


id | name | email  | staff
1    name1  email1   true
2    name2  email2   no
3    name3  email3   true
4    name4  email4   no


id | text | sender_id | receiver_id
1    text1    1            2 
2    text2    1            3
3    text3    1            2   
4    text4    3            2 

Note has 2 Foreign Keys to the User, sender_id and receiver_id.

I want to get in a Select(one if possible) the data (name, email, staff) of both the sender and the receiver/.

I tried :

  SELECT N.text, U.name, U.email from Note as N 
    LEFT JOIN User as U on Note.sender_id = U.id where U.staff is True ...

but this way I'm getting the sender only.

1 Answer 1


You must use the User table twice:

SELECT N.text, S.name, S.email, R.name, R.email
FROM   Note as N 
   LEFT JOIN User as S on N.sender_id = S.id where S.staff is True       
   LEFT JOIN User as R on N.sender_id = R.id where R.staff is True

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.