How to retrieve a child node's immediate parent node from a tree table?

Hello
Hi,
I have a category_subcategories table, and I would like to know how to construct a sql and sub-sql for retrieving a child node's immediate parent node.
Here is my first part of the sql, it only returns the node "Flash"'s parent and its grand-parents:
SELECT parent.category_name, node.lft, node.rgt
FROM category_subcategories AS node,
category_subcategories AS parent
WHERE node.lft > parent.lft AND node.lft < parent.rgt
AND node.category_name = 'FLASH'
ORDER BY parent.lft;
| name |
| ELECTRONICS |
| PORTABLE ELECTRONICS |
| MP3 PLAYERS | |
how can I modify this query so that it returns Flash' parent - 'MP3 Players'?
Thanks a lot
Sam

Hi,
This is an Oracle forum. If you're not iusing Oracle, make that clear. Always say what version of your softwate you're using, whether it's Oracle or anything else.
Whenever you have a question, post a little sample data (CREATE TABLE and INSERT statements), and the results you want from that data. Explain how you get those results from that data.
It looks like you're using the Nested Sets technique for modeling a tree. To get the parents of given nodes, do something like this:
SELECT        parent.category_name
,       node.lft
,       node.rgt
FROM        category_subcategories      node     -- Can't use AS with table alias in Oracle
,       category_subcategories      parent
WHERE        parent.lft      IN (
                    SELECT     MAX (lft)
                    FROM     category_subcategories
                    WHERE     lft     < node.lft
                    AND     rgt     > node.rgt
AND        node.category_name          = 'FLASH'
ORDER BY  parent.lft; This should work in Oracle 8.1 and up. (I can't actually test it unless you post CREATE TABLE and INSERT statements for some sample data). You may need to modify the syntax a little for your database.
785102 wrote:
Hello,
I tried to implement the solution as follow:
mysql> select parent.*
-> from category_subcategories as parent
-> having parent.lft =
-> (select max(parent.lft) from
-> (SELECT parent.category_name, parent.lft, parent.rgt
-> FROM category_subcategories AS node,
-> category_subcategories AS parent
-> WHERE node.lft > parent.lft AND node.lft < parent.rgt
-> AND node.category_name = 'Sofa'
-> ORDER BY parent.lft
-> )
-> );
ERROR 1248 (42000): Every derived table must have its own alias
mysql>
But I got an error.
What is wrong with it?What does the error message say?
Apparantly, in your system (unlike Oracle), every sub-query must have a name. Try something like this:
select      parent.*
from      category_subcategories as parent
having      parent.lft = (
               select      max(parent.lft)
               from     (
                         SELECT        parent.category_name
                         ,       parent.lft
                         ,       parent.rgt
                         FROM        category_subcategories      AS node,
                                category_subcategories      AS parent
                         WHERE        node.lft      > parent.lft
                         AND        node.lft      < parent.rgt
                         AND        node.category_name = 'Sofa'
                         ORDER BY  parent.lft     -- Is this a waste of effort?
                    )  AS got_name_lft_and_rgt
              )     AS got_lft
;What is the purpose of having the inner sub-query, the one I called got_name_lft_and_rgt?
Also, in Oracle, an ORDER BY clause in a sub-query doesn;t guarantee that any super-queries will keep that order. Why do you have an ORDER BY clause in the sub-query, and not in the main query?

Similar Messages

  • How to add an item object as a child for a specified parent node in AdvancedDataGrid in Flex?

    Hi all,
              This is the code, to add a object as a child into a specified parent node in AdvancedDataGrid in flex.
    <?xml version="1.0" encoding="utf-8"?><mx:Application
    xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="onCreationComplete()" width="100%" height="100%">
    <mx:Script><![CDATA[
    importmx.controls.Alert; 
    importmx.collections.IHierarchicalCollectionViewCursor; 
    importmx.collections.IHierarchicalCollectionView;  
    importmx.collections.ArrayCollection; [
    Bindable]private var objectAC:ArrayCollection = newArrayCollection(); 
    //This method is used to construct the ArrayCollection 'flatData' 
    private function onCreationComplete():void{
    var objOne:Object = newObject(); objOne.name =
    "Rani"; objOne.city =
    "Chennai";objectAC.addItem(objOne);
    var objTwo:Object = newObject(); objTwo.name =
    "Rani"objTwo.city =
    "Bangalore";objectAC.addItem(objTwo);
    var objThree:Object = newObject(); objThree.name =
    "Raja"; objThree.city =
    "Mumbai";objectAC.addItem(objThree);
    //This method is used to add one object as a child item for the parent node 'Rani' 
    private function addChildItem():void{
    var dp:IHierarchicalCollectionView = groupedADG.dataProvider asIHierarchicalCollectionView;  
    varcurent:IHierarchicalCollectionViewCursor = groupedADG.dataProvider.createCursor();  
    var dummyParentNode:Object = {name:"Rani", city:"New Delhi"};  
    var obj:Object = null; 
    while(curent.current){
    // To get the current node objectobj = curent.current;
    // Add Child item, when depth = 1 and Node name should be "Rani" 
    if (curent.currentDepth == 1 && obj["GroupLabel"] == "Rani"){
    dp.addChild(curent.current, dummyParentNode);
    curent.moveNext();
    groupedADG.dataProvider = dp;
    groupedADG.validateNow();
    groupedADG.dataProvider.refresh();
    ]]>
    </mx:Script> 
    <mx:AdvancedDataGrid id="groupedADG" x="10" y="15" designViewDataType="tree" defaultLeafIcon="{null}" sortExpertMode="true" width="305" > 
    <mx:dataProvider> 
    <mx:GroupingCollection id="gc" source="{objectAC}"> 
    <mx:grouping> 
    <mx:Grouping> 
    <mx:GroupingField name="name"/> 
    </mx:Grouping> 
    </mx:grouping> 
    </mx:GroupingCollection> 
    </mx:dataProvider> 
    <mx:columns> 
    <mx:AdvancedDataGridColumn headerText="Name" dataField="name"/> 
    <mx:AdvancedDataGridColumn headerText="City" dataField="city"/> 
    </mx:columns> 
    </mx:AdvancedDataGrid> 
    <mx:Button x="10" y="179" label="Open the folder 'Rani'. Then Click this Button" width="305" click="addChildItem()" /> 
    </mx:Application> 

    Hi,
    It's not possible to 'append' a StringItem or a TextField (or any other lcdui.Item object) to a Canvas or GameCanvas. You can only draw lines, draw images, draw text, etc etc, on a Canvas screen. So, you can only 'simulate' the look and feel of a TextField (on a Canvas) by painting it and adding source code for command handling (like key presses). However, this will be quite some work!!
    lcdui.Item objects can only be 'appended' to a Form-like Displayable.
    Cheers for now,
    Jasper

  • Copy values from one Parent node to other Parent Node

    Hi all,
    I have a 2 Parent node each having 3 child nodes. I want to copy the values of all the attributes of all the child nodes of one Parent Node to corresponding other node.
    Both the Parent Nodes as well as their Child Nodes have different name but their attributes have same name.For ex:
    Parent Node -A
    Child Nodes - a, b,c
    Child Node "a" has attributes "x" and "y"
    Parent Node -B
    Child Nodes - d,e,f
    Child Node "d" has attributes "x" and "y" .
    Now I want to copy the values od attributes "x" and "y" from one Parent Node to other Parent node.
    Please help me out.
    Helpful answers will be rewarded.
    Thanxs in advance...

    Hi Jin,
    To use copy service API, u need to satisfy 2 condition for the attributes of source node and target node:
    1. The name of the attribute should be same (including the case of the name)- Abc is different from ABC
    2. Type of the attribute should also be the same.
    copy elements works for copying values from Model node to context and does not work vice-versa. To enable the copying of context node to model node, use copycorresponding API.
    Eg:
    int contextNodeSize = wdContext().node<contextNodeName>().size();
    for(int i = 0; i < contextNodeSize; i++)
         <modelNodeName> modelObject = new <modelNodeName>();
         <contextNodeName>Element contextObject = wdContext().node<contextNodeName>().get<contextNodeName>ElementAt(i);
         WDCopyService.copyCorresponding(contextObject, modelObject);
    This will copy the values from Context Node to Model Node.
    Hope this helps you.
    Regards,
    Poojith MV

  • How to get Immediate Parent Node of UID

    Hi,
    Iam implementing a search criteria over the basis of UID.
    Suppose if I will have a UID within LDAP Directory then I have to search for its property. If this property is not available within the context of UID then I want UID's Immediate parent so I can search through it.
    My Question is how can I get the immediate parent of any UID without knowing it.
    Thanks & Regards:
    Durrab Jami Khan

    Hi,
    Iam implementing a search criteria over the basis of UID.
    Suppose if I will have a UID within LDAP Directory then I have to search for its property. If this property is not available within the context of UID then I want UID's Immediate parent so I can search through it.
    My Question is how can I get the immediate parent of any UID without knowing it.
    Thanks & Regards:
    Durrab Jami Khan

  • How to retrieve a backup of an external hard drive from time machine if there is a drive failure of the external HD?

    Hi,
    I have a time caspule that I use as my backup for Time machine.
    My itunes folder is on an external drive and When I do my backups, I connect my external to my mac so that my itunes folder will be backed up.
    When I do the back up, I know its backing up the external due to the size of the backup.
    but if my external were to fail, how do I retrieve the back up of the external? From what I can tell the drive has to be connected to the mac when connecting to time machine to access the back up files for the external. But if the drive is dead, how do I retrieve my files?

    budden10, please try this:
    Disconnect the external drive to simulate it not working or having failed
    Open Time Machine on your Mac and wait a few minutes for your backups to load fully
    Go back in time and select a date when you were backing up the external drive
    Now look at the Finder window and locate your Mac on the left side of the window under DEVICES
    Click on your Mac
    What do you see in the window there just to the right?

  • Af:tree Master child relation ,but showing child id's as parent node vice

    Hi ,
    Am using adf 11G 11.1.1.5
    I have a small requiement .
    Am using af:tree , where i display childId's . Onclick of child it i have to show popup with tree structure where i will show parentid as node and childId's as child nodes
    i have created view link between child and parent views.
    Now isssue is when i selected childId in table (i mean a checkbox is given where user check the child Id and fire button ).On dat action am calling popup with tree structure .BUT here childId's are displaying like Parent nodes and parentId's as child node.
    any suggestion . if want i will drop the code

    i knew somewhere i was messed up .
    There is only viewlink between, Parent and child .NO FK ,these are not related database table (Entity Object.).
    simple query's which are made from same table , but base on Parent/Root col i have show data in tree structure way.
    Just like
    ParentId Chilld id
    100 jhon
    100 max
    100 adam
    101 jack
    103 jill
    103 marven
    Now it will show in table like
    jhon
    max
    adam
    jack
    jill
    marven
    If i click max i mean check box and fire button , i have to show tree structure like below
    100
    jhon
    max
    adam
    As max parentid is 100 , i have to show all the childid which have 100 as parentid.
    any suggestion plz , me struck here to handel

  • Partial selection of child does not keep parent node selected

    Hi All,
    Please help! I have a checkbox JTree which is working fine in all regard as I want except one condition i.e. if all child(leaf) of a parent are not selected parent gets deselected i.e. if we uncheck any child(leaf) node parent will get unselected even if there are some child are selected. I am posing code for the model. let me know if I need to post other codes also
    tree.setModel(new DefaultTreeModel(rootNode1) {
        public void valueForPathChanged(TreePath path, Object newValue) {
            Object currNode = path.getLastPathComponent();
            super.valueForPathChanged(path, newValue);
            if ((currNode != null) && (currNode instanceof DefaultMutableTreeNode)) {
                DefaultMutableTreeNode editedNode = (DefaultMutableTreeNode) currNode;
                CheckBoxNode newCBN = (CheckBoxNode) newValue;
                //CheckBoxNode newCBN1 = (CheckBoxNode) newValue;
                if (!editedNode.isLeaf()) {
                    int i=0;
                    //for (int i = 0; i < editedNode.getChildCount(); i++) {
                      while(i < editedNode.getChildCount()){
                         System.out.println("child count root"+editedNode.getChildCount());
                         System.out.println("child count root i"+i);
                        DefaultMutableTreeNode node = (DefaultMutableTreeNode) editedNode.getChildAt(i);
                        CheckBoxNode cbn = (CheckBoxNode) node.getUserObject();
                        cbn.setSelected(newCBN.isSelected());
                        if(!editedNode.getChildAt(i).isLeaf())
                        for(int j=0;j<editedNode.getChildAt(i).getChildCount();j++)
                         System.out.println("child count roottt"+editedNode.getChildCount());
                         System.out.println("child count root j"+j);
                         DefaultMutableTreeNode node1 = (DefaultMutableTreeNode) editedNode.getChildAt(i).getChildAt(j);
                         CheckBoxNode cbn1 = (CheckBoxNode) node1.getUserObject();
                         //cbn1.setSelected(true);
                         cbn1.setSelected(newCBN.isSelected());
                        i++;
                else{
                    boolean isAllChiledSelected = true;
                   for (int i = 0; i < editedNode.getParent().getChildCount(); i++) {
                        DefaultMutableTreeNode node = (DefaultMutableTreeNode) editedNode.getParent().getChildAt(i);
                        CheckBoxNode cbn = (CheckBoxNode) node.getUserObject();
                        if(!cbn.isSelected()){
                            isAllChiledSelected = false;
                    if(isAllChiledSelected){
                        DefaultMutableTreeNode node = (DefaultMutableTreeNode)editedNode.getParent();
                          CheckBoxNode cbn = (CheckBoxNode) node.getUserObject();
                        cbn.setSelected(isAllChiledSelected);
                if (!newCBN.isSelected()) {
                    DefaultMutableTreeNode node = (DefaultMutableTreeNode) editedNode.getParent();
                    if (node.getUserObject() instanceof CheckBoxNode)
                        ((CheckBoxNode) node.getUserObject()).setSelected(false);
              /*if (!newCBN.isSelected()) {
                    DefaultMutableTreeNode node = (DefaultMutableTreeNode) editedNode.getParent();
                    if (node.getUserObject() instanceof CheckBoxNode)
                        ((CheckBoxNode) node.getUserObject()).setSelected(false);
    });

    Hi Thomas,
    Sorry for late reply due to weekend.
    I had already tried your suggestion but it is not working. Do not know why? here is the code.
    else {
      int countselection=0;
    int t=editedNode.getParent().getChildCount();
                   for (int i = 0; i < editedNode.getParent().getChildCount(); i++) {
                        DefaultMutableTreeNode node = (DefaultMutableTreeNode) editedNode.getParent().getChildAt(i);
                        CheckBoxNode cbn = (CheckBoxNode) node.getUserObject();
                        if(cbn.isSelected()){
                            countselection= countselection+1;
                    if(icountselection==0 ){
                        DefaultMutableTreeNode node = (DefaultMutableTreeNode)editedNode.getParent();
                          CheckBoxNode cbn = (CheckBoxNode) node.getUserObject();
                        cbn.setSelected(false );}
    else if(countselection==1 && countselection<=t)
    DefaultMutableTreeNode node = (DefaultMutableTreeNode)editedNode.getParent();
                          CheckBoxNode cbn = (CheckBoxNode) node.getUserObject();
                        cbn.setSelected(true );
    }}

  • How to retrieve all the users along with their password from LDAP

    Hello,
    Can anyone let me know how to retrieve and list all the user along with their password from LDAP.
    Thanks

    Hi Prashant,
    I have limited experience with Synchronization, but I agree with you - if you need to synchronize Passwords, you need to have the Password in clear Text.
    If you trying to build your own Synchronization Solution using any of the avaliable LDAP APIs, I don't think you can ever retrieve a user's Password in clear text.
    However, I did come across an interesting article & I hope you find it useful :-
    http://www.oracle.com/technology/obe/obe_as_10g/im/configssl/configssl.htm
    I am not sure if SSL is necessary - If you have a look at Metalink Note 277382.1 ( How to Configure OID External Authentication Plug-In for Authentication Via Microsoft Active Directory (MS AD) ), teh question asked by oidspadi.sh for the same is asnwered as "N".
    Regards,
    Sandeep

  • How to split all the fields of output ls-l from an internal table

    Hi all,
    Using ls-l command i have brought the file attributes of a file like its read and write permissions,creation date ,path etc in a internal table.
    Now how to split all these fields from the internal table or what should be the splitting criteria.
    The field contents of internal table are like this:
    -rw-rw----    1  devadm     sapsys     18360    apr  29......so on
    I want to split this into different fields.
    Kindly suggest.
    Thank You.

    Hi,
    I think the delimiter will be space. For date alone (Apr 29) you need to concatenate after the string has been split.
    Thanks and regards,
    S. Chandramouli

  • How to return from Child Page to Immediate Parent Page

    Hi All,
    I have created a custom OAF page and linked the same with 3 standard OAF pages(Lets say Standard-Page1, Standard-Page2, Standard-Page3) in such a way that whenever I click the GO button in any of those standard pages it navigates to my custom page.
    As of now when I click the BACK button in the custom page it navigates back to Standard-page1(Because i have given the page1 Path in the pageContext.ForwardImmediately) only even though if I would have opened my custom page from standard-Page2 or 3.
    I need to understand what should I do to navigate back to the exact standard page from which the custom page has been opened.
    Any help on this would be greatly appreciated.
    Many thanks in advance!
    Kind Regards,
    Myvizhi

    Hi Sumit,
    Thanks for your kind reply. I tried another way because we will not have that Standard AM in the Custom Page. The other way is like, getting the standard page URL into a variable and passing it as a session value and getting that session value into a variable in the Custom Page. Then passing that variable in the place of URL in the following way:
    In the Standard Page passing URL variable into a session value:
    String s4 = pageContext.getCurrentUrlForRedirect();
    pageContext.putSessionValue("*previousPageUrlForList*", s4);
    In the Custom Page getting session value into a variable and using :
    String valuefromsession =(String)pageContext.getSessionValue("*previousPageUrlForList*");
    pageContext.forwardImmediately(
    valuefromsession,
    null,OAWebBeanConstants.KEEP_MENU_CONTEXT,
    null,
    null,
    true, // retain AM
    OAWebBeanConstants.ADD_BREAD_CRUMB_NO);
    Kind Regards,
    Myvizhi

  • Financial Reporting:How to supress G/L Accounts numbers at parent node

    Hi,
    I have Local Hirearchy created in Query Designer in ROWS using "New selection" under a "structure."
    Direct cost (Node: 1)
    >Salaries(Node: 2)
    >Bench(Node: 2)
    and so on.
    Let say Salaries comprised of 3 G/L accounts and Bench has 2 G/L accounts.
    Direct Cost
    >Salaries(Node: 2)   G/L account :  1001, 1002,1003    
    >Bench(Node: 2)   G/L account :  1004 ,1005
    Now when i display the report , i see all the G/L accounts under Direct cost (1001,1002,1003,1004, 1005)
    and under salaries (1001  , 1002,1003 ) and under Bench (1004,1005).
    My requirement is I dont want to display any G/L accounts under Direct cost and it should only show under its Child nodes.
    The info object OGL_ACCOUNT is also in the rows.
    How do i achieve this?
    Regards,
    Mayank

    Hi ,
    you need to create a hierarcy in query designer .
    Create one restricted keyfigure with
    >Salaries(Node: 2) G/L account : 1001, 1002,1003
    new restricted key figure 1001 with gl account 1001
    next 1002
    next 1003
    and other Restricted keyfigure with
    >Bench(Node: 2) G/L account : 1004 ,1005
    new restricted key figure 1004with gl account 1004
    next 1005
    now create a calculated key figure and add both salaries and bench
    i hope you got it .
    thanks,
    pk

  • Same child value under different parent node and these also some childs

    Hi guys,
    Can anyone suggest me on the hierarchy creation with duplication of node data as
    follow  we have
    one text node under 3 childs and these have same data value &
    these have some child values 
    here we have problem with same data node as not accept the following childs..
    pls help me on this.....

    Hi.
    have a look on this link
    http://help.sap.com/erp2005_ehp_04/helpdata/EN/fb/b74d3c006f0a1de10000000a11402f/frameset.htm
    hope it helps.

  • How to find latest child for a given parent in same table?

    More details:
    Here I am giving an example -
    Orig_ID     Chg_to_ID
    A     B
    B     C
    C     D
    D     Null
    From source I use to get Orig_ID values, using Orig_ID value have to find latest Child(Chg_to_ID) to that at any level.
    Latest child identify by Null value in the column "Chg_to_ID".
    If I get B --> need to replace B with D. I may get any value A or B or C or D -- but at an end I have to replace those values with 'D', since it is latest for any of those parents.
    I tried to use "Connect By Prior", but it is tooo slow ofcourse query not returned after 10min also. Plz advise.

    First time every employee will be assingend an ID and may changed/merged to another ID basing on some other conditins. So, any time first assigned ID may changed to new ID and will be updated to another column "Chg_to_ID" as winner ID and at the same time one more records will be created with new ID as ID and Null in "Chg_to_ID".
    In my first post, given an example, here pasting again:
    Orig_ID     Chg_to_ID
    A-------------->B
    B-------------->C
    C-------------->D
    D-------------->Null
    In detail: One employee first assigned ID as "A" after wards changed to "B". At that time data would be like below
    Orig_ID     Chg_to_ID
    A-------------->B
    B-------------->Null
    After that B change to C, now it looks like this:
    Orig_ID     Chg_to_ID
    A-------------->B
    B-------------->C
    C-------------> Null
    For each change one record will be inserted.
    My requirement is -- Orig_ID may get A or B or C, but I need to replace those with "C", since it is latest child. For latest child "Chg_to_ID" is NULL.
    Plz let me know for any clarifications.

  • How to retrieve a message into an html page passed from a servelt?

    am new to servlet.
    i have a Login.html contains a form having username and a password field.when the form is submitted it goes to VerifyServlet for authentication.
    now if the user provide the correct username and password i authenticate him into a new servlet called UserhomeServlet which i have already done. but if the password is incorrect i wanted to take him back to the Login.html with a Error message printed on it passed from the VerifyServlet. i dont know how to do that.
    pls tell me if you have any idea.

    Hi ,
    Try the following in your VerifyServlet doPost / doGet method.
    //for simplicity i have defined name & pwd in the same file and compared values from the login.html //
    //you can implement your logic //
                     if (name.equals(login)&& pwd.equals(pass)){
              //redirect to UserhomeServlet
                          else {
                   out.println("Invalid Login");
                   RequestDispatcher rd = req.getRequestDispatcher("/html/login.html");
                   rd.include(req,res);
         }bye for now
    sat

  • How to retrieve User Description for a particular MDM User from Console ?

    In my Application i  have to retrieve User Descripton(a field) for the MDM Users  from Console. I am using MDM Java Api 1(MDM4j) in my application. Is there any way i can retrieve MDM User Description from Console without using MDM Admin API?

    Hi Namrata,
    Sorry, I have a different perspective from you (I don't work with the Java API). So, you can ignore what I said about the protocols. That's lower-level than what you would care about.
    The correct thing to do is to use the Admin API to get the users, as you are doing. If you have to log in twice, it might be because you're using the old Java API.
    Please verify that you're using these packages:
    mdm-core.jar, mdm-common.jar, mdm-protocol.jar, mdm-data.jar, mdm-admin.jar
    versus the old API, which was called mdm4.jar.
    Thanks,
    Cleopatra

Maybe you are looking for

  • Lock tables when load data

    Are there any way to lock tables when i insert data with SQL*Loader? or oracle do it for me automatically?? how can i do this? Thanks a lot for your help

  • HT4796 Hi, I am trying to migrate my data from a windows 7 enterprise machine to a new macbook air.

    The two computers connect fine over the wifi network, but the mac only shows one user file - the administrator.  There are no error messages. It doesn't show mine (even though I am logged on as me on the PC laptop).  I don't have a seperate administr

  • Y50 touchpad let/right buttons not working correctly.

    When I try to do a left or a right click my touchpad will only register it half the time. Sometimes have to click around 5-10 times before it will work. I can usually get the left click to work after only a couple of clicks, but the right click hardl

  • Calling a function from an external AS file

    I create a AS file that contains my DAO functions. I imported the class into my application, but what do I have to do to call one of its functions? In my ProjectDAO.as I have updateProject(projectID:Number), in my mxml I have a button that calls that

  • Hyperlink Link to Email

    The iWeb hyperlink email solution allows you to configure the reciepent and the subject however it does not appear to support default text which would appear in the body of the email. Is there an iWeb solution for this?  Ant..