SELECT `users`.title,`users`.user_id, `mail`.`to_id`, MAX(`mail`.`time`) AS `time`
FROM `mail`
LEFT JOIN `users` ON `mail`.`to_id`=`users`.`user_id`
WHERE `mail`.`user_id`='" . USER_ID . "'
GROUP BY `mail`.`to_id`
ORDER BY MAX(`mail`.`time`) DESC