MySQL easy solution (CASE)
Code\n\nSELECT\n    id\n    , CASE\n        WHEN p_id IS NULL THEN \'Root\'\n        WHEN id IN (SELECT p_id from Tree) THEN \'Inner\'\n        ELSE \'Leaf\'\n 
# Code\n```\nSELECT\n    id\n    , CASE\n        WHEN p_id IS NULL THEN \'Root\'\n        WHEN id IN (SELECT p_id from Tree) THEN \'Inner\'\n        ELSE \'Leaf\'\n    END AS type\nFROM Tree;\n\n```
['MySQL']