I am creating a category and subcategory system. Suppose I have a main category such as 'Food'
. It has a child such as 'Drinks'
, Drinks has another child 'Juice'
, Juice has child 'Organic'
and Organic has the child 'Grape Juice'
. So basically Food
is the main parent and the structure is Food>Drinks>Juice>Organic>Grape Juice
. Now I have stored them on the category table like below:
As you can see I have a immediate parent id such as pid
. Now how I can select all the category name under the main category Food
from this table? I will be given the cat_id
1. So, how I can use this cat_id
to track all of the sub categories and their child, sub child etc from the table? What will be the SQL? Can anyone help? Thanks in advance.