I' trying to retrieve nested comments, I'm able to get all replies recursively for single commend by below code.
SELECT id, name, parent_id
FROM comments
WHERE id = 2
UNION
SELECT id, name, parent_id
FROM (SELECT * FROM comments ORDER BY id) sort,
(SELECT @pv := 2) init
WHERE find_in_set(parent_id, @pv)
AND length(@pv := concat(@pv, ',', id))
Above query works but it only returns specific id. I want to retrieve all comments like saying where post_id=1
but couldn't figure it out how we do it. I would be appreciate if anyone help.
EDIT: I want to get all comments belongs to a post and their replies recursively.
comments table has id,name,parent_id etc.. fields..