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