我有一张聊天 table 。
消息 I senderID I recipentID I date
我想通过对话获取最新消息组的查询。 (例如,如果 'senderID = 1 and the recipentID = 2' 与 'senderID = 2 and the recipentID = 1' 是同一个对话)
最佳答案
您可以在中使用
。 MySQL 支持带有 in
的元组,所以这是一种方法:
select c.*
from chats c
where (least(senderID, recipentID), greatest(senderID, recipentID), date) in
(select least(senderID, recipentID), greatest(senderID, recipentID), max(date)
from chats c
group by least(senderID, recipentID), greatest(senderID, recipentID)
);
关于MYSQL 查询 : get the latest date with grouped by data,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52478276/