Get root, inner, and leaf nodes from a table?
<p>Given a table of nodes (their Ids and their Parent Ids), how can I get all root, inner, and leaf nodes?</p>

<p>Here's what I have so far:</p>

<p>Root Nodes</p>

<pre><code>SELECT Id, "Root" FROM NodeTable
WHERE ParentId IS NULL;
</code></pre>

<p>Inner Nodes</p>

<pre><code>???
</code></pre>

<p>Leaf Nodes</p>

<pre><code>SELECT N1.Id, "Leaf" FROM NodeTable N1
LEFT JOIN NodeTable N2 ON N1.Id = N2.ParentId
WHERE N2.ParentId IS NULL;
</code></pre>

<p>Is this correct? Is there a way I can do this in just one query?</p>