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 - Sorting/Ordering by a differnt field.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-29-09, 06:46
mythix mythix is offline
Registered User
 
Join Date: Jun 2002
Posts: 63
Question Nested Set - Sorting/Ordering by a differnt field.

I was wondering if there was an easy way to order a nested set by a column other than `left` or `right` whist still maintaining the hierachical order? Obviously it would be possible to do this after retrieval - but because of the potential nunber of rows this may be too intensive.

For example given the tree:

A (1,8)
- D (2,3)
- C (4,7)
- - B (5,6)

I would want to retrive the result in order:

A (1,8)
- C (4,7)
- - B (5,6)
- D (2,3)

I guess storing these in order is a potential solution - however there are several fields on which ordering should be possible.

Any thoughts?

thanks
Reply With Quote
  #2 (permalink)  
Old 09-30-09, 07:02
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
Can you provide the CREATE TABLE statements, some sample data (in the form of INSERT statements) and the expected results from that sample data please?
__________________
George
Twitter | Blog
Reply With Quote
  #3 (permalink)  
Old 09-30-09, 09:09
mythix mythix is offline
Registered User
 
Join Date: Jun 2002
Posts: 63
No problem

Code:
CREATE TABLE  `wats_svn_40`.`jos_whelpdesk_tree` (
  `grp` varchar(100) NOT NULL default '',
  `type` varchar(100) NOT NULL default '',
  `identifier` varchar(100) NOT NULL default '0',
  `parent_type` varchar(100) default NULL,
  `parent_identifier` varchar(100) default NULL,
  `lft` int(11) default NULL,
  `rgt` int(11) default NULL,
  `description` varchar(255) default NULL,
  PRIMARY KEY  (`grp`,`type`,`identifier`),
  KEY `PARENT` (`parent_type`,`parent_identifier`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
I should point out that this table is designed to hold more than one tree (separated by the grp field). This table is a sort of index for rows held in other tables - the type field identifies the type of node we are talking about.

In terms of alphabetical order I would only ever be extracting a branch that is made up entgirely of the same type of node.

The table also include a refernce directly to the parent node.

Attached is some sample data (was too big to include easily in the message body text).

To be honest i have been looking around teh internet and am thinking that this is no easy task without post processing.
Attached Files
File Type: txt tree.txt (6.7 KB, 77 views)
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