Best April deals - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
The very basics
Infinite looping
Processing trees with recursive CTEs
Processing graphs with recursive CTEs
Summary
34. Exercise 2

Instruction

Nice! Let's try an exercise with a tree.

Exercise

Look at the folder table. Each folder has an id, a name, and the ID of its parent folder, which is the folder containing the current folder.

Show four columns: id, name, parent_id and path. The last column should contain the path to the folder, starting with '/' and followed by all folder names, separated by '/'. At the end of the path, there should be the name of the given folder and a slash ('/').

As an example, folder B, which is in the root folder A, would have a path like this: /A/B/.

The root folder has a NULL parent_id. For that folder, the path should be: /.