469,127 Members | 1,341 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,127 developers. It's quick & easy.

Can I recurse through a table to get child values?

Hi, I have a table which has a list of ingredients (ingredientid, ingredientname, parentid) where the parentID is another ingredient within the same table.

Can I do a function which gives me all the children of a particular ID (and their children)?


So, for example in the attached image, if I wanted to get all the children (and their children) for Vodka(5) I should get:

Absolut Vodka(24) > Stolichnaya Red(39) > Level Vodka(36) > 42 Below Vodka Pure(35)

which all have a parentID of 5, but also I want to get Absolut Kurant which has a parentID of 24...ie the chain is:

Vodka(5) > Absolut Vodka(24) > Absolut Kurant(28)

and the complete result of the query would be:
Absolut Vodka,Absolut Kurant,Stolichnaya Red,Level Vodka,42 Below Vodka Pure

To build the tree you see in the image I use functions in code, but for this I really need to be able to do it in mySQL.

Can I do these kind of functions? ANy ideas would be appreciated.
Sep 17 '08 #1
0 1210

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by PAUL | last post: by
3 posts views Thread by anjee | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.