グループごとの最大値
が必要です 、Messages
に参加することで見つけることができます 各グループの識別(最大)タイムスタンプを識別するサブクエリへのテーブル:
SELECT Message.request_id,
Sender.username AS sender_name,
Receiver.username AS receiver_name,
Message.message AS last_message,
Message.timestamp AS last_timestamp
FROM Message NATURAL JOIN (
SELECT request_id,
sender_id,
receiver_id,
MAX(timestamp) timestamp
FROM Message
GROUP BY request_id, sender_id, receiver_id
) t
JOIN User Sender ON Sender.id = Message.sender_id
JOIN User Receiver ON Receiver.id = Message.receiver_id
ORDER BY Message.request_id, last_timestamp DESC
sqlfiddle でご覧ください 。