View Single Post

   
  #2 (permalink)  
Old 03-04-2008, 07:24 AM
Captain Paralytic
 
Posts: n/a
Default Re: Question about nested set extraction order

On 3 Mar, 12:42, Maxxx <non...@nohost.xxx> wrote:
> Hi again,
>
> Some time ago I asked for a suggestion about nested set query and I had a
> really valuable help, thank you again to all.
> I'm developing my application using the queries managing nested set
> method and I have another "curiosity" about an additional feature I would
> like to have in the data result from the query. I think my "request" will
> not be possible to realize, but I would try to ask. :-)
>
> Based to this article:
>
> http://dev.mysql.com/tech-resources/...ical-data.html
>
> the following query will extract tree data as reported:
>
> SELECT node.name, (COUNT(parent.name) - 1) AS depth
> FROM nested_category AS node,
> nested_category AS parent
> WHERE node.lft BETWEEN parent.lft AND parent.rgt
> GROUP BY node.name
> ORDER BY node.lft;
>
> +----------------------+-------+
> | name | depth |
> +----------------------+-------+
> | ELECTRONICS | 0 |
> | TELEVISIONS | 1 |
> | TUBE | 2 |
> | LCD | 2 |
> | PLASMA | 2 |
> | PORTABLE ELECTRONICS | 1 |
> | MP3 PLAYERS | 2 |
> | FLASH | 3 |
> | CD PLAYERS | 2 |
> | 2 WAY RADIOS | 2 |
> +----------------------+-------+
>
> This query order data by the "lft" field for have all the nodes ordered
> in "descending" way and this is very good for "make" a tree inside a
> control. I would to know if it will be possible to have another "sub-
> order" insithe this data. I would like to have this data in this same
> main "descending" order but, inside every "sub-level depth group" have
> also ordered the name alphabetically. For use the same example I would to
> have the data axtreacted ordered in the following mode:
>
> +----------------------+-------+
> | name | depth |
> +----------------------+-------+
> | ELECTRONICS | 0 |
> | PORTABLE ELECTRONICS | 1 |
> | 2 WAY RADIOS | 2 |
> | CD PLAYERS | 2 |
> | MP3 PLAYERS | 2 |
> | FLASH | 3 |
> | TELEVISIONS | 1 |
> | LCD | 2 |
> | PLASMA | 2 |
> | TUBE | 2 |
> +----------------------+-------+
>
> Is this possible to have a query making this result? I think no, but is
> better to ask to experts.
> Thank you again for the help


Did you try adding node.name to the ORDER BY clause? If so what
happened?
Reply With Quote