A good use of Common Table Expressions
The problem I had a situation recently were I needed to find a set of data that was structured logically as a tree and was stored as a single table. I had an initial id and I needed to search for children of this id. Then I needed to use the children’s ids and search for their children. This continued until there were no more children of an id. This structure could have a plethora of different sets of children. For examples the boxes below represent an id and I only show three levels deep but the level depth was not restricted: Once I found all of an id’s children, I needed to do some manipulation of this data. To make this problem easier to understand and use a ubiquitous example, the ids will be folders and there are files (stored in another table) associated with the folders. Therefore for this problem, I need to find all the child folders for a specific folder, the files associated with the initial folder and the files associated with all the found child folder