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
hvad du har brug for er et unikt samtale-id mellem chat-partnerne. Jeg har simuleret dette med underforespørgslen, håber dette hjælper