选择列值最新唯一的行

时间:2018-03-20 09:19:20

标签: sql sqlite

请帮助找到合适的查询。

任务:表包含短信。从每个对话中选择最新的短信

表格示例

enter image description here

查询结果

enter image description here

提前多多感谢

2 个答案:

答案 0 :(得分:2)

以下是您问题的解决方案:

SELECT MAX(id) AS ID, conversationId, Max(date) AS Date 
FROM Table_name 
GROUP BY conversationId

答案 1 :(得分:1)

使用带有相关性的子查询

select * 
from table t
where date = (select max(date) from table where conversationid = t.conversationid)