SQL | Basic | Using SELECT & UNION
\nSELECT id, \n\t"Root" AS type FROM Tree WHERE p_id IS NULL\nUNION\nSELECT id, \n\t"Leaf" AS type FROM Tree WHERE p_id IS NOT NULL AND id NOT IN (SELECT DISTIN
```\nSELECT id, \n\t"Root" AS type FROM Tree WHERE p_id IS NULL\nUNION\nSELECT id, \n\t"Leaf" AS type FROM Tree WHERE p_id IS NOT NULL AND id NOT IN (SELECT DISTINCT(p_id) FROM Tree WHERE p_id IS NOT NULL )\nUNION\nSELECT id, \n\t"Inner" AS type FROM Tree WHERE p_id IS NOT NULL AND id IN (SELECT DISTINCT(p_id) FROM Tree WHERE p_id IS NOT NULL);\n\n```\nPlease upvote if you found this useful :)
['Union Find', 'MySQL']