I have a mysql table that holds comments. The comments can have sub-comments, but only one level down (there’s an optional ‘parent’ attribute, and a comment’s parent can’t have a parent of its own). I want to paginate such data, like this:
Take the first, say 10 top-level comments (with the page offset), and also their sub-comments, where available.
The obvious solution is to fetch the 10 comments, and then their sub-comments with an IN clause, but I feel like this is the wrong way to do it (or at least there’s a better way).
Is there a better way of achieving this?
I think the IN subquery is probably going to be your best bet: