The question I'm hearing is 'How do I store hierarchical data in a relational DB?' (of course I could be missing the point.) If not, take a peek at Managing Hierarchical Data in MySQL for some more information.

This article applies to more than just MySQL of course. I personally really like the 'nested set' structure for hierarchies that don't change a lot. Enjoy!

Update: I've just discovered a slightly more verbose example that compares the adjacency list model and the nested set.

One thing I haven't seen discussed, yet, is the idea of adding another 'dimension' to the tree. There is a 'left' and 'right' for the nested set values, but what about adding a 'z' field? (depth) I wonder if the penalties of updating the nodes could be reduced with something like that. Just thinking out loud.

Kurt

PS: What better way to warm up your fingers than hammering out some Perl code! :)


In reply to Re: database table advice by whereiskurt
in thread database table advice by coldfingertips

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.