Does anyone know how to do a self join farther than one level deep? i.e. I have a category table, and the category has a label, an id and a parentId.
SELECT a.label AS parent_label, b.label AS child_label FROM category AS a, category AS b WHERE a.id = b.parentId;
And that is fine if the child does not have any children. But if I have autos > seats > leather
When I run the query I get:
1 Auto Seats
2 Seats Leather
I have written a recursive function that will follow it all the way down, but I'm curious if a self join can do it without php.
Ideally, I would like to say something like,
please choose a category:
Autos ::
Autos :: Seats
Autos :: Seats :: Leather
Thanks for any ideas!