我有一个带有 MESSAGE 表的数据库,它包含我的所有消息。我需要找到所有最后的对话消息。
该表包含以下字段: Id (int) From (int) To (int) Date (date) Message (varchar)
我需要找到一个返回所有最后消息的查询。例如:
1 -> 3 : This is a first message; yesterday
3 -> 1 : This is the last one; today
1 -> 2 : Another message with 1 and 2; some time
3 -> 5 : Some message i don't need; some time
我需要找到:
"3 -> 1 : This is the last one; today"
"1 -> 2 : Another message with 1 and 2; some time"
我希望我的意思很清楚......我已经可以通过以下查询找到与我交谈的用户:
在此示例中,用户的 Id = 47
select distinct m.To from MESSAGE m Where m.From = 47 union select distinct m2.from From MESSAGE m2 where m2.To = 47
谢谢!