0

Okay, so I have a structure which can look like this

d
├── a
│   ├── f_2
│   └── f_3
├── b
│   ├── f
│   │   └── f_5
│   └── f_4
├── c
└── f_1

But there can be a lot of sub-folders and files. However, in the database they are stored as: (id, parent_id, type, name) where type is the file/folders id, parent_id is the parent folder, type tells if the entry is a file or folder, and name is an ASCII string representing the name of the folder/file.

What I want to do is being able to give an id of any folder in the tree, let us say in this case d and I want to select ids of all files and folder which are children of the folder d include their sub children.

I have looked through the mySQL documentation on hierarchical structures but I cannot see a solution based on this.

Lars Nielsen
  • 2,005
  • 2
  • 25
  • 48
  • https://stackoverflow.com/questions/20215744/how-to-create-a-mysql-hierarchical-recursive-query – Romain B. Feb 21 '18 at 10:18
  • @Shadow this is not a duplicate of that question, the question only ask for single level children, which my question does not. So I disagree that this is a duplicate as it cannot be solved in the same manner – Lars Nielsen Feb 21 '18 at 11:49
  • 1
    @LarsNielsen nope, you misread the duplicate question. The level of hierarchy is undefined, can be any. There are several answers that handle unlimited levels of hierarchy. – Shadow Feb 21 '18 at 13:30

0 Answers0