If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Nested Set model - Get child node with parent

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-13-09, 17:45
dyip dyip is offline
Registered User
 
Join Date: Jan 2009
Posts: 15
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!
Reply With Quote
  #2 (permalink)  
Old 02-13-09, 19:54
guelphdad guelphdad is offline
Registered User
 
Join Date: Mar 2004
Posts: 440
Have you read: this article which is where your table looks like it came from?
Reply With Quote
  #3 (permalink)  
Old 02-13-09, 20:32
dyip dyip is offline
Registered User
 
Join Date: Jan 2009
Posts: 15
I did but the answer is not in there
Reply With Quote
  #4 (permalink)  
Old 11-11-10, 06:53
rrozema rrozema is offline
Registered User
 
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.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On