MySQL Forums :: General :: Expert question : Tree query : How to format the output of a self JOIN not to generate an additional column ?


Advanced Search

Expert question : Tree query : How to format the output of a self JOIN not to generate an additional column ?
Posted by: Corporation One ()
Date: January 08, 2010 01:59PM

How to format the output of a self JOIN not to generate an additional column ?

I am not sure if this is a newbie question but I haven't used SQL much :

For the following Tree :

myTree
NodeID NodeType ParentID ChildID

given the tree

5 6
\/
8


8 1 0 0
...
11 2 5 8
12 2 6 8

Using "Left join ... as ... on" syntax recommended for trees results into

Child Parent1
Child Parent2

whereas I need a simple result set :

Child1
Parent1
Parent2
Child2
Parent3
Parent4

Child needs to come up first followed by related parents :

8 1 0 0
11 2 5 8
12 2 6 8

the pseudo code would be :

select * from myTree where nodetype = 1;

as rows found immediatly retrieve parents :

select from myTree where ChildID = CurrentNodeID


What mySQL statement would allow such query ?

Thanks,

One

Options: ReplyQuote


Subject Written By Posted
Expert question : Tree query : How to format the output of a self JOIN not to generate an additional column ? Corporation One 01/08/2010 01:59PM
Re: Expert question : Tree query : How to format the output of a self JOIN not to generate an additional column ? Peter Brawley 01/08/2010 09:15PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.