0

I have two tables one table contain category name,category_id other table contain category_id and parent_id. so the data is stored like that for particular category_id we need to find parent_id until parent_id is null.

It simply like category/leafcategory/l2/l3.

to find the parent of l3 we have to loop the table untill the parent_id is null. and where the parent_id is null that category_id is parentcategory.

  • Can you share sample records, expected output and what you've tried so far? – Techie Jul 11 '15 at 15:50
  • Possibly best method for such problem would be stored procedure – insanebits Jul 11 '15 at 15:53
  • There is similar solution with MySQL stored procedures http://dba.stackexchange.com/questions/7147/find-highest-level-of-a-hierarchical-field-with-vs-without-ctes it needs little modification but would work for you. Or if category tree is really small you can get away by building tree using programming language you're using to access database – insanebits Jul 11 '15 at 15:57

0 Answers0