SQL查询根父子记录

发布于 2024-09-05 11:07:07 字数 405 浏览 2 评论 0原文

我们有具有父子关系的嵌套文件夹。我们使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

煞人兵器 2024-09-12 11:07:07

如果您知道父文件夹的信息,那么根文件夹将与父文件夹相同。或者,如果父文件夹没有根文件夹,则根文件夹将是父文件夹本身。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文