[Solved] Create hierarchical data from 2 tables

Has nothing to do with recursion. Basically you can get what you want with UNION SELECT ProdId as MarkerId, ProdName as MarkerName, NULL as MarkerParentId from t1 UNION ALL SELECT OrdId as MarkerId, OrdName as MarkerName, ProdId MarkerParentId from t2 ORDER BY MarkerId, MarkerParentId 3 solved Create hierarchical data from 2 tables