Say I have the mdl_course_categories table:
select cat.id, cat.name, cat.parent, cat.depth, cat.path
from mdl_course_categories cat
| id | name | parent | depth | path |
|----|------|--------|-------|----------|
| 1 | a | 0 | 1 | /1 |
| 2 | b | 0 | 1 | /2 |
| 3 | c | 1 | 2 | /1/3 |
| 4 | d | 3 | 3 | /1/3/4 |
| 5 | e | 4 | 4 | /1/3/4/5 |
| 6 | f | 0 | 1 | /6 |
| 7 | g | 6 | 2 | /6/7 |
| 8 | h | 7 | 3 | /6/7/8 |
| 9 | i | 3 | 3 | /1/3/9 |
| 10 | j | 7 | 3 | /6/7/10 |
How can I generate the breadcrumbs as per below? I'm a complete rookie to SQL, and have no experience managing hierarchial data. I had a look at this answer, but was unable to translate it to my table and situation. Thanks in advance!
| id | name | parent | depth | path | breadcrumb |
|----|------|--------|-------|----------|---------------|
| 1 | a | 0 | 1 | /1 | a |
| 2 | b | 0 | 1 | /2 | b |
| 3 | c | 1 | 2 | /1/3 | a - c |
| 4 | d | 3 | 3 | /1/3/4 | a - c - d |
| 5 | e | 4 | 4 | /1/3/4/5 | a - c - d - e |
| 6 | f | 0 | 1 | /6 | f |
| 7 | g | 6 | 2 | /6/7 | f - g |
| 8 | h | 7 | 3 | /6/7/8 | f - g - h |
| 9 | i | 3 | 3 | /1/3/9 | a - b - i |
| 10 | j | 7 | 3 | /6/7/10 | f - g - j |