Creo que esto es lo que buscas.
SELECT messages.*
FROM
(SELECT MAX(lastseen) AS lastseen,IF ('Tom' = `from`,`to`,`from`) as otheruser FROM messages
WHERE 'Tom' IN (`from`,`to`) GROUP BY otheruser
)
AS latest INNER JOIN messages ON latest.lastseen = messages.lastseen
AND (('Tom' = messages.from AND latest.otheruser = messages.to)
OR
('Tom' = messages.to AND latest.otheruser = messages.from))
ORDER BY messages.lastseen
DESC,`read`='no' limit 10
simplemente reemplace 'Tom' con su variable
Esto devolverá los últimos 10 usuarios que enviaron mensajes a 'Tom' o 'Tom'.