SELECT * FROM msg_messages m
JOIN msg_status s on m.messageId = s.messageId
JOIN msg_threads t ON t.threadId = m.threadId
JOIN users u ON u.userId = s.userId
WHERE t.threadId = 1
GROUP BY u.userId ORDER BY `m`.`date` DESC
问问题
250 次
3 回答
-1
这个怎么样:
SELECT * FROM msg_messages m
JOIN msg_status s on m.messageId = s.messageId
JOIN msg_threads t ON t.threadId = m.threadId
JOIN users u ON u.userId = s.userId
GROUP BY u.userId
having max (`m`.`date`)
ORDER BY `m`.`date` DESC
我修改了我的查询
having max (`t`.`threadId`)
至
having max (`m`.`date`)
于 2015-11-18T10:31:17.753 回答
-1
您可以在 DESC 之后使用 LIMIT 1 ,然后您将获得最后一条记录。示例: DESC 限制 1;
于 2015-11-18T10:32:19.543 回答
-1
试试这个代码
SELECT * FROM msg_messages m
JOIN msg_status s on m.messageId = s.messageId
JOIN msg_threads t ON t.threadId = m.threadId
JOIN users u ON u.userId = s.userId
WHERE t.threadId = 1
GROUP BY u.userId ORDER BY `m`.`date` DESC LIMIT 0,1
于 2015-11-18T10:30:20.920 回答