title: SQL - Multi level self join
body: <p>i have a table which has parent child relationship like this - Isfinal column suggests that it is the final element of that level</p>
  
  <pre><code>ID    name    ParentId    Isfinal
  1     abc       0           No
  2     acd       1           No
  3     ads       1           No
  4     xyz       2           No
  5     xxy       2           Yes
  6     plm       3           No
  7     ytr       4           Yes
  8     lks       6           Yes
  </code></pre>
  
  <p>I am trying to write a dynamic query which will give the child element of that ID.</p>
  
  <p>E.G.</p>
  
  <p>If I select 2 then it should give the result as - </p>
  
  <pre><code>ID    name    ParentId    Isfinal
  4     xyz       2           No
  5     xxy       2           Yes
  7     ytr       4           Yes
  </code></pre>
  
  <p>Is it possible with self join?</p>