My input is like this
and i need output like this
I tried using join/Left joins but its showing only immediate parent. like below
SELECT ChildUserType.Id as child, ParentUserType.Id as parent
FROM tablea AS ChildUserType
LEFT JOIN tablea AS ParentUserType
ON ChildUserType.main_Line_id = ParentUserType.Id;
anyone has any idea how i can get the desired output



