1select id,
2 name,
3 parent_id
4from (select * from products
5 order by parent_id, id) products_sorted,
6 (select @pv := '19') initialisation
7where find_in_set(parent_id, @pv)
8and length(@pv := concat(@pv, ',', id))