Say I have the following tables:
users
-----
id
username
messages
-----
id
sender (id user)
recipient (id user)
msg
In a single query, how can I get the name of the sender, the name of the recipient, and the message?
I would basically need to join the users table twice, but not sure how that would be possible..
SELECT
s.username as sender,
r.username as recipient,
msg
FROM
messages m join users s on (m.sender = s.id)
join users r on (m.recipient = r.id)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With