, , , , ... , , . . , sql (@variables), @varRow , reset 1 (, PreQuery ID FIRST). , HAVING, @varRow count < 6 MOST 5 .
, , WHERE (, /, ) INNER, "PreQuery".
select straight_join
PreQuery.*,
@varRow := if( @LastPost = PreQuery.PostID, @varRow +1, 1 ) CommentRow,
@LastPost := PreQuery.PostID PostID2
from
( select
posts.id PostID,
posts.body,
posts.CreatedAt,
u1.id UserID,
u1.DisplayName NameOfPoster,
c.id,
c.userid CommentUserID,
c.text CommentText,
u2.DisplayName CommentUserName
from
posts
join users u1
on posts.ownerUserID = u1.id
LEFT JOIN comments c
on posts.id = c.PostID
join users u2
on c.userid = u2.id
where
posts.id = TheOneParentIDYouWant
OR posts.parentid = TheOneParentIDYouWant
order by
posts.ID,
c.id desc ) PreQuery,
(select @varRow := 0, @LastPost = 0 ) SQLVars
having
CommentRow < 6
order by
PreQuery.postid,
CommentRow
--- EDIT ---
, , " " , . / , ...
Post -> User (to get posting user name )
Post -> Comment (on Common Post ID -- left joined)
Comment -> User ( to get commenting user name)
, , , @vars . HAVING , 5, .