SELECT messages.* FROM messages, (SELECT MAX(id) as lastid FROM messages
WHERE receiver = 13 OR sender = 13
GROUP BY CONCAT(LEAST(receiver,sender),'.',GREATEST(receiver,sender))) as conversations
WHERE id = conversations.lastid
ORDER BY timestamp DESC
vad du behöver är ett unikt konversations-ID mellan chattpartnerna. Jag har simulerat detta med underfrågan, hoppas detta hjälper