0
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 

这是给我每条记录的第一个索引的查询。但我想获得每个组的最新索引.. 我尝试了很多方法,但结果一无所获。用户: 这是没有摸索的

这是在摸索

这就是我分组后想要的

这就是给我的

4

3 回答 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 回答