Easy 2 lines query.
ApproachThe given table has the records of edges between nodes in a tree. if a node has parent node as null then the tree node is a Root node. if a node is pres
<!-- # Intuition -->
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->
The given table has the records of edges between nodes in a tree. if a node has parent node as `null` then the tree node is a [Root node](https://en.wikipedia.org/wiki/Tree_(abstract_data_type)#Terminology). if a node is present in parent nodes column then it is a [Inner node / Internal node](https://en.wikipedia.org/wiki/Tree_(abstract_data_type)#Terminology). If the node is not present in the parent nodes then it is not a [Leaf node](https://en.wikipedia.org/wiki/Tree_(abstract_data_type)#Terminology).

# Logic
- if the node is not having parent it is `Root` node.
- if the node is a parent of another node it is a `Inner Node`.
- if the node is not a parent of any other node then it is a `Leaf Node`.

if the links don't work please visit [https://en.wikipedia.org/wiki/Tree_(abstract_data_type)#Terminology](https://en.wikipedia.org/wiki/Tree_(abstract_data_type)#Terminology)

please hit upvote if you like the content.
<!-- # Complexity -->
<!-- - Time complexity: -->
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

<!-- - Space complexity: -->
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```sql []
/* Write your PL/SQL query statement below */
select id, 
        case when p_id is null then 'Root'
        -- print Root when parent is null. 
        when id in(select distinct p_id from Tree) then 'Inner'
        -- print Inner Node when It is a parent to another element.
        else 'Leaf' end as "type"
        -- print Leaf if It is not a parent node of any node.
from Tree;
```
['Binary Search Tree', 'Database', 'Binary Tree', 'Oracle']