Jump to content

subselect to join


josoroma

Recommended Posts

I was studying nested set model:

MySQL AB :: Managing Hierarchical Data in MySQL

 

Everything goes cool, because of my mysql version, now im having nightmares trying to pass the following subselect to joins, any help is welcome:

 

 

SELECT node.name, (COUNT(parent.name) - (sub_tree.depth + 1)) AS depth

FROM nested_category AS node,

nested_category AS parent,

nested_category AS sub_parent,

(

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

AND node.name = 'PORTABLE ELECTRONICS'

GROUP BY node.name

ORDER BY node.lft

)AS sub_tree

WHERE node.lft BETWEEN parent.lft AND parent.rgt

AND node.lft BETWEEN sub_parent.lft AND sub_parent.rgt

AND sub_parent.name = sub_tree.name

GROUP BY node.name

HAVING depth <= 1

ORDER BY node.lft;

 

 

Thanks in advanced.

Link to comment
Share on other sites

Is the same query at the mysql website tutorial about:

Managing Hierarchical Data in MySQL

But this post doesnt let me to write the URL.

 

Is part of the subselect:

...

(

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

AND node.name = 'PORTABLE ELECTRONICS'

GROUP BY node.name

ORDER BY node.lft

)AS sub_tree

...

 

Any help is welcome with the sql conversion from subselect to join.

 

Thanks.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.