title: Recursive select in SQL
body: <p>I have an issue I just can't get my head around. I know what I want, just simply can't get it out on the screen.
  What I have is a table looking like this:</p>
  
  <pre><code>Id, PK UniqueIdentifier, NotNull
  Name, nvarchar(255), NotNull
  ParentId, UniqueIdentifier, Null
  </code></pre>
  
  <p>ParentId have a FK to Id.</p>
  
  <p>What I want to accomplish is to get a flat list of all the id's below the Id I pass in. </p>
  
  <p>example:</p>
  
  <pre><code>1   TestName1    NULL
  2   TestName2    1
  3   TestName3    2
  4   TestName4    NULL
  5   TestName5    1
  </code></pre>
  
  <p>The tree would look like this:</p>
  
  <pre><code>-1
    -&gt; -2
         -&gt; -3
    -&gt; -5
  -4
  </code></pre>
  
  <p>If I now ask for 4, I would only get 4 back, but if I ask for 1 I would get 1, 2, 3 and 5.
  If I ask for 2, I would get 2 and 3 and so on.</p>
  
  <p>Is there anyone who can point me in the right direction. My brain is fried so I appreciate all help I can get. </p>