Get all children by parent id and where clause in mysql
问题 I have a table that stores id and parent_id in same table. I want a recursive query that accepts parent_id as an argument and returns all child nodes with nth level. For this I am using this code and working properly for me. select id, name, parent from (select * from tablename order by parent, id) tablename, (select @pv := '1') initialisation where find_in_set(parent, @pv) > 0 and @pv := concat(@pv, ',', id) My problem start from here: I want to add WHERE clause with result set but unable to