我正在创建聊天(仅供两个人聊天,而不是“全局”),我的表格如下所示:
留言:
id | author | receiver | content | sent
其中作者和接收者是来自USERS的 id :
id | login | avatar
我想从消息的接收者和作者那里获得登录名和头像。我正在尝试这样的事情:
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
以及其他一些查询,但我只能获得一个登录名(接收者或作者)。有没有办法做到这一点?