MySQL Forums
Forum List  »  Stored Procedures

Re: nested lookup - query to get the respective descendents
Posted by: Rick James
Date: September 16, 2012 12:17AM

You are looking for not just the immediate children, but all descendents, correct? (I changed the Subject.)

Sorry, there is no SQL syntax for such.

Plan A: You have a loop in your code to descend until there are no more children.

Plan B: Do similar stuff in a Stored Procedure.

The code would probably be building a longer and longer list of PKs. This list would be put into a IN(...) clause.

You would start with $list = the PK of the top node. Then get a new value for $list from something like
SELECT  GROUP_CONCAT(PK ORDER BY PK SEPARATED BY ', ')
    FROM  area_lookup
    WHERE  parent IN ($list)
When the value stops changing, break out of the loop.

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: nested lookup - query to get the respective descendents
1101
September 16, 2012 12:17AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.