Simple MySQL Solution [using case]
\nselect id,\n    case when p_id is null then \'Root\'\n         when id in (select distinct p_id from tree) then \'Inner\'\n         else \'Leaf\'\n         en
```\nselect id,\n    case when p_id is null then \'Root\'\n         when id in (select distinct p_id from tree) then \'Inner\'\n         else \'Leaf\'\n         end as type\n    from tree\n```\n\t\n**OR**\n\n```\nselect id,\n    case when p_id is null then \'Root\'\n         when id not in(select distinct p_id from tree where p_id is not null) then \'Leaf\'\n         else \'Inner\'\n         end as type\n    from tree\n```
['MySQL']