SQL查询根父子记录
我们有具有父子关系的嵌套文件夹。我们使用MySQL MyISAM DB。 数据按以下方式存储在 DB 中。
每次在嵌套结构中创建子文件夹时,都会添加之前的parentID。我想要获取添加到层次结构中的文件夹的 RootFolderID,如下表所示。
FoldID ParentID |RootFolderID
-----------------|-------------------
1 0 | 0
2 1 | 1
3 2 | 1
4 3 | 1
5 4 | 1
请让我知道如何在每次创建文件夹后获取根文件夹ID并将其填充到RootFolderID列中。
谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您知道父文件夹的信息,那么根文件夹将与父文件夹相同。或者,如果父文件夹没有根文件夹,则根文件夹将是父文件夹本身。
if you know the parent folder's information, then the root folder will be the same as that of the parent. or, if the parent has no root folder, then the root folder will be the parent folder itself.