我正在使用mysql。我有一个名为'messages_received'的表。 这是特定用户的所有消息。我想做的是获取发件人列表(from_member_id基于chrnological order。
在这种情况下;数据就像
59
10697
1451
3704
997
答案 0 :(得分:0)
类似这样的事情:(未经测试)
select max(id), from_member_id
from messages_received
group by from_member_id
order by max(id) desc
这适用于sqlite 3.5.9,但似乎mysql不喜欢max
中的order by
所以:
select max(id), from_member_id
from messages_received
group by from_member_id
order by id desc
这也适用于sqlite 3.5.9,但我认为应该在mysql中工作
答案 1 :(得分:0)
select from_member_id, max(id)
from messages_received
group by from_member_id
order by max(id) desc
答案 2 :(得分:0)
我相信你想要:
SELECT DISTINCT(from_member_id) FROM messages_received ORDER BY id DESC
答案 3 :(得分:0)
试试这个:
SELECT DISTINCT from_member_id FROM messages_received ORDER BY id DESC;