我的消息传递架构如下
USER
id
name
MESSAGE
id
messagetitle
sender_id
receiver_id
我想显示带有发送方和接收方名称的
messagetitle
例如,MySQL查询应该显示:
+--------------+------------+--------------+
| MessageTitle | SenderName | Recievername |
+--------------+------------+--------------+
| Important | Raj | Vijay |
| Solution | Vijay | Raj |
+--------------+------------+--------------+
最佳答案
请为您的解决方案尝试以下sql:
SELECT
m.messagetitle AS MessageTitle
,u1.Name AS SenderName
,u2.Name AS Recievername
FROM MESSAGE m
INNER JOIN USER u1 ON u1.id = m.sender_id
INNER JOIN USER u2 ON u2.id = m.receiver_id
SQL FIDDLE DEMO
关于mysql - mysql查询以显示带有发送者和接收者的消息,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18162447/