I am building an e-commerce website in which category management plays an important role. The table structure for category is given below
category_id | category_name | parent_category_id
------------------------------------------------------
1 | Shoes | NULL
2 | Sports Shoes | 1
3 | Fila Shoes | 2
4 | Black Shoes | 3
parent_category_id is a foreign key reference to category_id
I want to backtrack from the last child to ancestors. I mean like this
Black Shoes-->Fila Shoes -->sports shoes --> shoes