472,143 Members | 1,422 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,143 software developers and data experts.

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 1251

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

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.