I have a table that looks like this:
ID |Name |Parent
1 |A |NULL
2 |B |NULL
3 |C |1
4 |D |1
5 |E |3
6 |F |5
I would like to have a view return this:
ID |Name |ParentNames
1 |A |
2 |B |
3 |C |A
4 |D |A
5 |E |A > C
6 |F |A > C > E
I tried to left join a view showing an IDs first parent and left joining it with itself but that didn't work.
Is there a way to do this without a stored procedure/function? I've got ~15k rows with ~0-5 parents each but I'd rather not hard code a maximum of 5 parents.