I have a table which has Categories and SubCategories which themselves can have subcategories so you can have
Cars -> Ford but also
Fruit -> Apple -> Granny Smith
So given a table like this
tblFoo
ID | ParentID | Position | Category
1 0 1 Fruit
2 0 2 Cars
3 1 1 Apple
4 1 2 Orange
5 1 3 Lemon
6 2 1 Ford
7 2 2 Nissan
8 2 3 Honda
9 3 1 Granny Smith
I would like to have a query to produce
ID | ParentID | Position | Category
1 0 1 Fruit
3 1 1 Apple
9 3 1 Granny Smith
4 1 2 Orange
5 1 3 Lemon
2 0 2 Cars
6 2 1 Ford
7 2 2 Nissan
8 2 3 Honda
Any help appreciated, thanks
Cars -> Ford but also
Fruit -> Apple -> Granny Smith
So given a table like this
tblFoo
ID | ParentID | Position | Category
1 0 1 Fruit
2 0 2 Cars
3 1 1 Apple
4 1 2 Orange
5 1 3 Lemon
6 2 1 Ford
7 2 2 Nissan
8 2 3 Honda
9 3 1 Granny Smith
I would like to have a query to produce
ID | ParentID | Position | Category
1 0 1 Fruit
3 1 1 Apple
9 3 1 Granny Smith
4 1 2 Orange
5 1 3 Lemon
2 0 2 Cars
6 2 1 Ford
7 2 2 Nissan
8 2 3 Honda
Any help appreciated, thanks