I'm creating chat ( just for two people to chat, not "global" ) and my tables look like this:
MESSAGES:
id | author | receiver | content | sent
where author and receiver are id's from USERS:
id | login | avatar
and i want to get login and avatar both from receiver and author of the message. I was trying with something like this:
SELECT * FROM
((SELECT messages.*,users.login as starter,users.avatar FROM messages
LEFT JOIN users ON messages.author = users.id
WHERE messages.receiver = 1)
UNION
(SELECT messages.*,users.login as test,users.avatar FROM messages
LEFT JOIN users ON messages.receiver = users.id
WHERE messages.author = 1)
ORDER BY id DESC LIMIT 5) tmp
ORDER BY id ASC
and few other queries but i could only get one login ( either receiver or author ). Is there any way to do that?