what kind of table structure is this?
I have created a table in which i have categories and products all in one table. i have id and pid column. Id is the main uniq id and pid is for the parent id. so for any first category the pid is 0 which means it is the top most.
consider for example the first category is id 1 and inside that i am creating another category say cat2. this would have id=2 and pid=1 and it can go like a tree structure.
Now i want to manipulate data in this table. for example i might start at any mid point and i want all its children as result set.
for example i have a structure like this... cat1->cat2->cat3->cat4->cat5
now i want to delete cat3 and its sub items. i have the id of cat3 and now i dont know how to form a query to list all its sub items or to fetch all its sub items ids to delete or to do other process.
also what is the term to such structure in database concepts?
Adjacency List model recursive deletion
I have a table with Adjacency List model.
Code:
id cop title pid
10 1 four 9
9 1 three 8
8 1 two 7
7 1 one 0
11 1 five 10
12 1 six 11
13 1 seven 12
14 0 test 10
This is categories and subcategories and products. A child will either be a sub category or a product. it can go upto 5 to 6 steps in deep but not more than that. But i want it in this model.Scripting is using PHP.
If i have to delete something in the middle then all its corresponding sub categories and products should be deleted. I have images for products so i will have to join with that table too.
What i need is a recursive code to delete this adjacency list model table.