SQL query root parent child records

Posted by Vish on Stack Overflow See other posts from Stack Overflow or by Vish
Published on 2010-06-08T09:36:35Z Indexed on 2010/06/08 9:42 UTC
Read the original article Hit count: 239

Filed under:
|
|
|
|

Hi, We have nested folders with parent-child relationship. We use MySQL MyISAM DB. The data is stored in the DB in the following manner.

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.

FoldID  ParentID |RootFolderID
-----------------|-------------------
1         0      | 0
2         1      | 1
3         2      | 1
4         3      | 1
5         4      | 1

Please let me know how to get the root folderID and populate it in the RootFolderID column after a folder is created each time.

Thanks.

© Stack Overflow or respective owner

Related posts about sql

Related posts about mysql