MySQL with NOT EXISTS
\nSELECT id, \nCASE WHEN p_id IS NULL THEN \'Root\' WHEN NOT EXISTS (\n    SELECT id FROM tree WHERE p_id = t0.id) \n    THEN \'Leaf\' ELSE \'Inner\' END as typ
```\nSELECT id, \nCASE WHEN p_id IS NULL THEN \'Root\' WHEN NOT EXISTS (\n    SELECT id FROM tree WHERE p_id = t0.id) \n    THEN \'Leaf\' ELSE \'Inner\' END as type from tree t0 order by id;\n```\n
['MySQL']