A hierarchical query
WITH RECURSIVE comment_tree (comment_id) AS ( SELECT comment_id FROM comment WHERE thread_id = 2 AND parent_comment_id IS NULL UNION SELECT c.comment_id FROM comment c, comment_tree ct WHERE c.parent_comment_id = ct.comment_id ) SELECT c.* FROM comment_tree ct JOIN comment c USING (comment_id);