Revisa esto. El valor que especificó en @pv :='6' debe establecerse en la identificación del padre que desea encontrar todos los descendientes de él.
también puede comprobar en vivo Demostración actualizada
select Parent, concat ( "{" ,Parent,",",GROUP_CONCAT(concat (child )SEPARATOR ','),"}") as Child
from (select * from #TableName
order by parent, child) s,
(select @pv := '6') initialisation
where find_in_set(parent, @pv) > 0
and @pv := concat(@pv, ',', child);
Para mostrar niños con padres en una columna, use la siguiente consulta:
select parent as child from tchilds where parent = @pv2
union
select Child
from (select * from tchilds
order by parent, child) s,
(select @pv2 := '6') initialisation
where find_in_set(parent, @pv2) > 0
and @pv2 := concat(@pv2,',', child)
háganos saber si todavía tiene alguna pregunta o inquietud.