title: How to do an upper recursive self-join in SQL Server?
body: <p>How can I do a recursive self-join in SQL Server ?
  I have a table like this:</p>
  
  <pre>
  TableID | ParentID
     1    |     NULL
     2    |        1
     3    |        1
     4    |        3
     5    |     NULL
     6    |        4
     7    |        6
  </pre>
  
  <p>I want to get the following results based on given <code>TableID</code> to get all the <code>ParentsID</code> related to the <code>TableID</code>, let's say I want to get all the parents for the <code>TableID = 6</code> : <br> </p>
  
  <pre>
  TableID
     6
     4
     3
     1
  </pre>
  
  <p>I'm stuck on this and i don't know how to get the result in SQL Query ...
  Hope to tell me the SQL Query to get the previous data </p>