| .:Ninja 2004-04-28, 10:41 am |
| Michele Locati wrote:
> I have a problem for which I can't see a fast solution:
>
> I have table A which contains, say, 2 fields:
> a_id
> a_parent
> a_parent is linked to the a_id field of the same table, to build a
> hirarchy with a deep which is not known in advance.
>
> I have another table, say B, with 2 fields:
> b_id
> b_a
> Where b_a links B to a record of A.
>
> My problem occurs when I have to retrieve all the B records associated
> with an A record identified with a_id, or any children/grandson/... of
> a_id in A.
>
> What I do now is to retrieve any children of a_id, and any children of
> the children, and so on. Then I select the record of B where b_a is
> any of this big list of children/grandson/....
>
> Anyone can see a faster solution?
>
> Thank you very much
>
> Michele
An off-topic comment. It seems a lot of people want to put tree-like data
into a MySQL database. Well, it so happens that MySQL and other SQL-like
databases don't lend themselves toward a tree-like structure. If you really
need a TREE, look into a directory service such as LDAP.
Just a random 2c worth...
..:Albe
--
http://www.ninja.up.ac.za
|