Anda harus mengetahui timestamp
terakhir nilai di setiap grup (subquery), lalu gabungkan subquery ini ke tabel -
SELECT t1.* FROM messages t1
JOIN (SELECT from_id, MAX(timestamp) timestamp FROM messages GROUP BY from_id) t2
ON t1.from_id = t2.from_id AND t1.timestamp = t2.timestamp;