2 solutions. one with case and other one is with union
\nPLEASE UPVOTE IF YOU LIKE\n\n```\nselect id,\n(\n    case\n        when p_id is null then \'Root\'\n        when id in (select p_id from tree) then \'Inner\'\
```\nPLEASE UPVOTE IF YOU LIKE\n```\n```\nselect id,\n(\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\n) as type\nfrom tree;\n\n\n# select id, \'Root\' as type  from tree  where p_id is null\n# union\n# select id, \'Inner\' as type from tree where p_id is not null and\n#         id in ( select p_id from tree where p_id is not null)\n# union\n# select id, \'Leaf\' as type from tree where p_id is not null and\n#         id not in ( select p_id from tree where p_id is not null)                       \n# order by id                                                \n\n
['Union Find', 'MySQL']