Hi, I encountered a similar use case when processing BoMs to resolve a hierarchical list of components. The query is not really recursive up to N-levels, but you need to specify one LEFT JOIN for every level you need to resolve:
In our case, we also had a base unit and a quantity, which we take from the deepest level, but I guess you may discard that part for your purpose.
Hierarchy: VERP -> HALB -> HALB -> FERT
--level1 = FERT (Fertigprodukt)
--level2 = HALB (Zwischenprodukt)
--level3 = HALB (Zwischenprodukt)
--level4 = VERP (Verpackung -> Baseprodukt)
--module = parent material description
--product = parent material id
SELECT a.parent_material_description, a.quantity_level1, a.parent_material_id, a.material_id_level1,
COALESCE(d.quantity_level4, c.quantity_level3, b.quantity_level2, a.quantity_level1 ) as quantity,
COALESCE(d.material_id_level4, c.material_id_level3, b.material_id_level2, a.material_id_level1 ) as material_id,
COALESCE(d.material_base_unit_level4, c.material_base_unit_level3, b.material_base_unit_level2, a.material_base_unit_level1 ) as material_base_unit,
b.material_id_level2, b.quantity_level2,
c.material_id_level3, c.quantity_level3,
d.material_id_level4, d.quantity_level4
FROM
(SELECT parent_material_description ,quantity as quantity_level1, parent_material_id, i.material_id as material_id_level1, material_base_unit as material_base_unit_level1 from inputTable i WHERE process_step = "FERT") a
LEFT JOIN
(SELECT quantity as quantity_level2, i.parent_material_id as parent_material_id_level2, material_id as material_id_level2,material_base_unit as material_base_unit_level2 from inputTable i WHERE process_step = "HALB") b
ON a.material_id_level1 = b.parent_material_id_level2
LEFT JOIN
(SELECT quantity as quantity_level3, i.parent_material_id as parent_material_id_level3, material_id as material_id_level3 , material_base_unit as material_base_unit_level3 from inputTable i WHERE process_step = "HALB") c
ON b.material_id_level2 = c.parent_material_id_level3
LEFT JOIN
(SELECT quantity as quantity_level4, i.parent_material_id as parent_material_id_level4, material_id as material_id_level4 , material_base_unit as material_base_unit_level4 from inputTable i WHERE process_step = "VERP") d
ON c.material_id_level3 = d.parent_material_id_level4
Credits to @daniel.kempter for the initial version of the query!! 