Coba ini. Anda dapat mengganti range_ menggunakan beberapa variabel yang disimpan di front-end Anda untuk pagination.
select child.MessageText from
(select @i:[email protected]+1 as range_, id, MessageText from messages, (select @i:=0) k where ParentMessageId is null order by id asc) parent
left outer join messages child on (parent.id = child.ParentMessageId or parent.id = child.id)
where parent.range_ between 1 and 3;