This style of notation can also be used with polyheirarchies (items w/ more than one parent), if you leave a couple of reserved characters for the notation. Here's an example that my teacher gave us for a class on thesaurus design:
Facet A : Subject A1 : Science A1.1 : Physics A1.1.1 : Optics Facet B : Grade Level B1 : High School B1.1 : 10th Grade

So, '10th grade optics' would be 'A1.1.1B1.1'. We use a delimitor between items, so we aren't restricted to subsets that each have a unique character in them, allowing for wider branching. (depth is still a problem when dealing with fixed line lengths)

The problem is, it's fine for humans to understand, but a little messy to sort on in SQL. You can get around this by adding another delimiter between facets, and ending every notation w/ a null heirarchy: ';A1.1.1.;B1.1.'. We can then get all items relating to 10th grade physics w/ LIKE '%;A1.1.%;B1.1.%', without fear of getting 'A1.10AB1.1', and still getting items that may have even more facets, eg a movie for 10th grade physics ';A1.1;B1.1;C1'

The only requirement is that you keep each of the facets in order. (what order doesn't matter, so long as you're consistent)

If you'd like a more complex example:

If we were to try to categorize cooking implements:

Facet A : Use A1 : Utensil A1.1 : Spoon A1.2 : Whisk A2 : Pan A2.1 : Roasting Pan A2.1.1 : Covered Roasting Pan A2.1.2 : Uncovered Roasting Pan Facet B : Material B1 : Metal B1.1 : Stainless Steel B1.2 : Aluminum B1.3 : Cast Iron B1.3.1 : Enameled Cast Iron B2 : Ceramic B2.1 : Glass B2.1.1 : Pyrex B2.2 : Stone Facet C : Size C1 : 1 qt C2 : 2 qt C2.1 : 2 qt, shallow

Therefore, a standard 9x13 pyrex dish would be ';A2.1.2.;B2.1.1.;C2.1.', and we could find all 2qt glass pans with '%;A2.%B2.1.%;C2.%'


In reply to Re^2: Trees in SQL, adjacency lists and sorting. by jhourcle
in thread Trees in SQL, adjacency lists and sorting. by BUU

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.