I have been using adjacency lists to solve problems with hierarchical data.
The algorithm is described in a relatively database independent way here:
And by the same author here: http://www.dbmsmag.com/9603d06.html
Includes a tiny bit more on nested set models.
From: Steve Folly [mailto:mysql@stripped]
Sent: Tuesday, January 13, 2004 1:59 PM
To: MySQL MySQL
Subject: Re: hierarchical records, I need some help!! ;(
On 13 Jan 2004, at 09:19, Victor Reus wrote:
> Hi again,
>> Second: specify what you mean with "all relations". Can you
>> share some sample data and sample output (that is: what
>> do you expect the query to return).
> Ok my table noms is like
> | id | int(11) | | PRI | [NULL] | auto_increment
> | reference | varchar(255) |
> | component | varchar(255) |
> The relation between refefence and component are like parent -> child
> Here is an example
> Table contains :
> ID REFERENCE COMPONENT
> 1 A004 B001
> 2 B001 C003
> 3 B001 D003
> (I have more records but only this are what i want to take as an
> So the relations are like a hierarchical tree:
> And i want one sentence that takes all the relations.
> The SQL statement result should be like:
> REFERENCE COMPONENT
> AOO4 B001
> B001 COO3
> B001 COO3
> .... ....
> Coudl somebody give me a tip to do it?.
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=1