I have 2 tables. items
and itemItems
itemItems
describes a many to many relationship between items
. I.e. a member of items
could have many children and they could have many children which in turn could have many children etc..
item:
itemID | more stuff ......
1 ...
2 ...
3 ...
4 ...
itemItems:
parentItemID | childItemID
1 2
1 3
2 4
I want to write a query that would recursively get all of the children under one root node.
I believe this is possible with something called a recursive join but I find the concept very confusing.... (similar to this question, but with sqlite not sql server and many to many not one to many)
I can get the first level (i.e. all children under one item) by doing the following
SELECT *
FROM items
INNER JOIN itemItems
ON items.itemID = itemItems.childItemID
WHERE itemItems.parentItemID = 1
How could I extend this to recursively get all the children's children etc...?