title: SQL query root parent child records
body: <p>We have nested folders with parent-child relationship. We use MySQL MyISAM DB.
  The data is stored in the DB in the following manner.</p>
  
  <p>Every time a child folder is created in the nested structure, the previous parentID is added. I want to get the RootFolderID of a folder which is added in the hierarchy as tabulated below.</p>
  
  <pre><code>FoldID  ParentID |RootFolderID
  -----------------|-------------------
  1         0      | 0
  2         1      | 1
  3         2      | 1
  4         3      | 1
  5         4      | 1
  </code></pre>
  
  <p>Please let me know how to get the root folderID and populate it in the RootFolderID column after a folder is created each time.  </p>
  
  <p>Thanks. </p>