Find path for nested categories in MySQL

This tutorial shows how to find the entire path from root to child for nested category and subcategory. We have a tables in such a way it contains unlimited level of categories and we have another column in the same table which holds the entire path for the nested categories.
Create a table

 

Dump some data into the table

 

Create procedure which will update the field cat_path using the category path

 

Usage Example

 

Output

find path in hierarchical categories

That’s all. Thanks for your reading. Please do not forget to leave a comment.

Soumitra

Software Professional, I am passionate to work on web/enterprise application. For more information please go to about me. You can follow on Twitter. You can be a friend on Facebook or Google Plus or Linkedin

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.