SQL Recipes
A FREE cookbook for SQL queries and examples
Register FAQ Search Today's Posts Mark Forums Read

SQL - Questions and Answers Have a SQL question? Post it here. First do a search to see if someone hasn't already answered it.

Go Back   SQL Recipes a FREE cookbook of SQL queries and examples > SQL queries and examples > SQL - Questions and Answers

Reply
 
LinkBack (1) Thread Tools Search this Thread
  1 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 07-04-2007, 06:22 AM
josoroma josoroma is offline
Junior Member
 
Join Date: Mar 2007
Posts: 2
josoroma is on a distinguished road
Default ANY dialect question:

subselect to inner join


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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Be the first to answer this question! Click on the 'Post Reply' button below.
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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

LinkBacks (?)
LinkBack to this Thread: http://www.sqlrecipes.com/sql_questions_answers/subselect_inner_join-138/
Posted By For Type Date
sql inner join example + inner join definition of inner join in the Free Online Encyclopedia @ JONLOK.INFO This thread Refback 03-29-2008 06:04 PM


All times are GMT. The time now is 09:11 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0
Copyright (c) 2006-2008 SQL Recipes

1 2 3 4 5 6 7 8