Check out example codes for "mysql 5.6 hierarchical recursive query". It will help you in understanding the concepts better.

Code Example 1

select  id,
        name,
        parent_id 
from    (select * from products
         order by parent_id, id) products_sorted,
        (select @pv := '19') initialisation
where   find_in_set(parent_id, @pv)
and     length(@pv := concat(@pv, ',', id))

Learn ReactJs, React Native from akashmittal.com