Try this...
Code:
SELECT p.postId, p.roomId, p.uniqueId, p.title, p.post, p.image, p.createdOn, r.created
FROM posts p
INNER JOIN (
SELECT u.postid, MAX(u.createdOn) AS created
FROM (
SELECT p.postId, p.createdOn
FROM posts p
WHERE p.deleted = 0
UNION
SELECT p.postId, c.createdOn
FROM comments c
LEFT JOIN posts p
ON p.postId = c.postId
WHERE p.deleted = 0
AND c.deleted = 0
UNION
SELECT p.postId, r.createdOn
FROM replies r
LEFT JOIN comments c
ON c.commentId = r.commentId
LEFT JOIN posts p
ON p.postId = c.postId
WHERE p.deleted = 0
AND c.deleted = 0
AND r.deleted = 0
) AS u
GROUP BY u.postid
) AS r
ON p.postId = r.postId
WHERE p.deleted = 0
ORDER BY r.created DESC
I think that's right. Note how using MAX( ) ensures that, indeed, you will get only one "created" date/time for each postid.
If I have the sense of it wrong, you might want to change MAX( ) to MIN( ).