Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2009
    Posts
    15

    Unanswered: Nested Set model - Get child node with parent

    Hi,

    I have a database that is based on the nested set model. what i'm trying to do here is to run a query that gets the "leaf" nodes and it's parents. For example my table looks like this:
    Code:
    +-----------------------+
    | name                         |
    +-----------------------+
    | ELECTRONICS              |
    |   TELEVISIONS              |
    |    TUBE                       |
    |     LCD                         |
    |     PLASMA                    |
    |  PORTABLE ELECTRONICS |
    |    MP3 PLAYERS            |
    |      FLASH                    |
    |    CD PLAYERS              |
    |    2 WAY RADIOS          |
    +-----------------------+
    I'm trying to get this....
    Code:
    +----------------------+-------+
    | name                       |  parent         |
    +----------------------+-------+
    | TUBE                         |     Television |
    | LCD                           |     Television |
    | PLASMA                     |     Television  |
    | FLASH                         |     MP3 Players |
    | CD PLAYERS                  |     PORTABLE ELECTRONICS|
    | 2 WAY RADIOS           |     PORTABLE ELECTRONICS |
    +----------------------+-------+
    Any help would be appreciated. Thanks in advnace!

  2. #2
    Join Date
    Mar 2004
    Posts
    480
    Have you read: this article which is where your table looks like it came from?

  3. #3
    Join Date
    Jan 2009
    Posts
    15
    I did but the answer is not in there

  4. #4
    Join Date
    Nov 2003
    Location
    Netherlands
    Posts
    1
    Any record's lft and rgt are always BETWEEN their parent's lft and rgt values. Your direct parent must be the one with the lft value closest to your's out of that set, i.e. the record with the highest lft value.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •