How to use order by with hierarchical query

I have a hierarchical query basically he brings an organization chart. We start with the Manager id, get everything that employees of the person. If the employee is also a Manager I want to get the employees of that person and turn them right after that person. I don't bother with the entire query but relevant part is:
       START WITH em.mgr_id = pi_mgr_id
      CONNECT BY nocycle PRIOR em.emp_id = em.mgr_id;
Where pi_mgr_id is a parameter passed to the procedure and the em is the alias of the emp_mgr_relationship table that contains emp_id and mgr_id. It works very well. What I want now is for employees who work for the same Manager appear in the order of name. The table that contains the names of the employees is an alias as pe and the name column is called name1. I added the following:
       START WITH em.mgr_id = pi_mgr_id
      CONNECT BY nocycle PRIOR em.emp_id = em.mgr_id
        order by pe.name1;
But what to put the entire list in the order of name. What I want is for the employees who work for the same manager be in name order. We're going to the manager that I want to the body is named Frank. I want to get it
EMP_NAME    MGR_NAME
Allen       Frank
Beth        Frank
Alex        Beth
Charles     Beth
Ed          Beth
Dean        Frank
George      Frank
Benny       George
David       George
Sam         George
Dan         Sam
Harry       Sam
John        Sam
Terry       George
James       Frank
Ken         Frank
Mike        Ken
Warren      Ken
How can I get the list in order?

Published by: kendenny on July 28, 2010 07:31

Make use of the ORDER of Friars and SŒURS clause in the hierarchical queries to define the order of child columns.

START WITH em.mgr_id = pi_mgr_id
      CONNECT BY nocycle PRIOR em.emp_id = em.mgr_id
        *order siblings by name1;*

Tags: Database

Similar Questions

  • How to use spell checking with magic mouse

    How to use spell checking with magic mouse

    Hello

    The mouse is not intended to be used with the spell checker.

    The mouse settings available in system preferences > mouse

    Spelling and grammar can be checked in the Edit menu in most applications.

    In addition, shortcuts keyboard.

    Command:

    And the command;

  • How to use windows update with browser firefox4

    How to use windows update with browser firefox4

    You MUST use Internet Explorer to access http://windowsupdate.microsoft.com.

  • How to use windows scan with the new canon printer is connected and the copy and printing, but can't seem to be able to use the technique of scan windows

    How to use windows scan with my new canon MX 922 printer.  It is conncected and copying and printing but can't seem to use the windows scan option, the cannon that which for me is slow thanks

    All in one, type printers (print, copy, scan) usually have a very specific set of instructions during the installation.  If not followed exactly the probability is that the scanner will not work.

    Canon: http://www.usa.canon.com/cusa/consumer

    Download and read the Setup instructions for your model, have you followed the instructions exactly, more precisely when to connect the printer / scanner during installation of the software process?

    J W Stuart: http://www.pagestart.com

  • How to use AS operator with my requriment query

    Hi all

    I have a requirement as follows

    EMPID ENAME SAL JOB
    ------------------------------------------------------------------------------------

    10 RAJ KAMAL MANAGER 25000
    20 REZZIK NIZAR CLERK 4000
    CHRISTINE GUPTA ANALYST 20000 30
    ASHUTOSH GUPTA DEVELOPER 10000 40
    ASHUTOSH 50 NAYAR PROGRAMMER 15000


    I'm looking enames I need to get the full name, even if I search with just a single LETTER/WORD immaterial the order they exist in the name I need to get the full name. (INFACT WORD comparison)

    ex:
    (1) select * from emp where ename like '% ka.

    I get:
    10 RAJ KAMAL MANAGER 25000
    20 REZZIK NIZAR CLERK 4000

    This isn't what I need I need just Word camparision no comparision letters let me tell you...

    Select * from emp where ename like 'amal %.

    Even for this ill request to get the same result... is not my option to go...

    I need just word comparison with letter of departure and immaterial to the position of the word in the name

    If it is possible to do with the query please let me know...

    Thanking you
    Julien Vishwanatham

    Or maybe

    SQL>  with e as (select 10 as empid, 'RAJ KAMAL' as ename, 'MANAGER' as job, 25000 as sal from dual union all
               select 20, 'KAMAL RAJ NAYAK', 'CLERK', 4000 from dual union all
               select 30, 'NARENDAR GUPTA', 'ANALYST', 20000 from dual union all
               select 40, 'ASHUTOSH GUPTA', 'DEVELOPER', 10000 from dual union all
               select 50, 'ASHUTOSH IMKAL', 'DEVELOPER', 10000 from dual union all
               select 60, 'ASHUTOSH NAYAR', 'PROGRAMMER', 15000 from dual
    )
    ---
    ---
    select *
    from e
     where regexp_like(ename,'(^| )ka(.*)( |$)','i')
    /
         EMPID ENAME           JOB               SAL
    ---------- --------------- ---------- ----------
            10 RAJ KAMAL       MANAGER         25000
            20 KAMAL RAJ NAYAK CLERK            4000
    
    2 rows selected.
    
  • Help with hierarchical query

    I'm trying to parse each string inside of individual characters. For this, I used the link by the hierarchical query clause. I am not able to use connect by correctly. Here is my example.

    with the CBC as)

    Select 1: the nurse, 'abc' double union all Str

    Select 2: the nurse, '123' Str of all union double

    Select 3: the nurse, "pqr xyz" dual union all Str

    Select option 4: the nurse, 'john doe' double Str

    )

    Select the level, homobasidiomycetes, substr(s.str,level,1) as chr

    s of the CBC

    connect nocycle level < = length (homobasidiomycetes)

    /

    The above query returns 3 028 lines when I want that 21. Adding a distinct to select, it's what I want.

    with the CBC as)

    Select 1: the nurse, 'abc' double union all Str

    Select 2: the nurse, '123' Str of all union double

    Select 3: the nurse, "pqr xyz" dual union all Str

    Select option 4: the nurse, 'john doe' double Str

    )

    Select distinct level, homobasidiomycetes, substr(s.str,level,1) as chr

    s of the CBC

    connect nocycle level < = length (homobasidiomycetes)

    order by str, level

    /

    For a large data set I could end up with several million rows before the separate would lead. So, how can I restrict the connection by clause to go within each line.

    Assuming that the AI is the primary key, you could do this:

    with src as (
      select 1 as rn, 'abc' as str from dual union all
      select 2 as rn, '123' as str from dual union all
      select 3 as rn, 'pqr xyz' as str from dual union all
      select 4 as rn, 'john doe' as str from dual
    )
    select level,
          s.str,
          substr(s.str,level,1) as chr
    from src s
    connect by level <= length(s.str)
              and prior rn = rn
              and prior dbms_random.value is not null;
    

    See DBMS_RANDOM.value in a hierarchical solution for string to table? for an exchange of views around the case.

  • Hierarchical data, how to aggregate over levels in hierarchical query?

    Hello

    I hope someone can help me.

    I held in a data table ("" what part was built in what other part of when when? "')
    ID parent_id build_in build_out
    1 NULL NULL NULL
    2/1 2010 2012
    3 2 2011 2013
    4 2 2013 NULL

    What are the parts is stored in a separate table.

    Now I want to know when when which part was built in the first level, in the example, I want to know that
    1 was simply a part of 1
    2 was part of 1 between 2010 and 2012
    3 was part of 1 between 2011 and 2012
    4 has never been a part of 1

    I tried several approaches - if there is a fixed number of levels between the types, I am interested I can do using joins and more/less (similarly as some nvl). Unfortunately this is not always the case (some parts appear on several levels).
    If I'm only interested in the parts that are never deleted, I can get by using a style of connect request and get the current configuration. But I can't seem to understand the time connecting part to the high level in such a query, or even filtering absurd combinations (like "4 in 1" in the example above). I could deal with the data recovered outside the database, but I prefer not.

    Is there a way to obtain the hierarchical data with an aggregate (min, max) for all levels?

    What version of Oracle you are on?

    In 11.2.x, you can use the recursive subquery factoring. Something like

    with t (id, parent_id, build_in, build_out) as (
    select 1, null, null, null from dual union all
    select 2, 1, 2010, 2012 from dual union all
    select 3, 2, 2011, 2013 from dual union all
    select 4, 2, 2013, null from dual
    )
    , c1 (root_id, id, parent_id, build_in, build_out) as (
    select id, id, parent_id, 0, 9999
    from t
    where parent_id is null
    union all
    select root_id, t.id, t.parent_id
    , greatest(nvl(t.build_in,0), nvl(b.build_in,0))
    , least(nvl(t.build_out,9999), nvl(b.build_out,9999))
    from c1 b, t
    where b.id = t.parent_id
    )
    select * from c1
    where build_in < build_out
    ;
    ROOT_ID ID    PARENT_ID  BUILD_IN  BUILD_OUT
    ------- ----- ---------- --------- ----------
    1       1                0         9999
    1       2     1          2010      2012
    1       3     2          2011      2012      
    

    With a hierarchical query by using the syntax connection, you could do something like

    select * from (
    select connect_by_root id as root, id
    , greatest(nvl(build_in,0), nvl(prior build_in,0)) as max_in, least(nvl(build_out,9999), nvl(prior build_out,9999)) as min_out
    from t
    start with parent_id is null
    connect by parent_id = prior id
    )
    where max_in < min_out
    ;
    

    but it is not powerful enough. This version compares the dates between a current and previous levels, but the recursive subquery is to compare the dates in the current level for the winners of the comparisons to the previous level. Not sure if it's an important distinction for your needs, however.

    If you are on 11.2 I advise to use the recursive subquery factoring. If this isn't the case, you can try the link by version.

    Kind regards
    Bob

  • Satellite A210 - how to use the muldimedia with other than Media Player buttons

    Hello

    is it really not possible to use media keys (Play, Pause, FF) on top of my laptop for an application other than Windows Media Player?
    Is there a reason for this? I would like to control Winamp with this button.

    It seems quite sensless to restrict access to a SINGLE application of HUNDREDS available, a then it is the multimedia player that is not used by most people.

    I have the Satellite A210 Notbook.

    Can you tell my how to control my winamp with these buttons?

    Greetings from Robert

    Hello, Robert

    Unfortunately, there is no solution at the moment. If you check this forum, you will find several very interesting discussions on the multimedia buttons and Winamp player. The fact is that some people have found the solution for older models of laptops running Windows XP Home edition. Winamp has offered the plugin must be installed.

    We now have the new situation. Your laptop is running latest Vista OS and I didn t find any plugin that can help. Problem is that your laptop is designed for Windows Vista preinstalled OS contains all the necessary plugins for Windows media player running under the operating system preinstalled.

    Is any kind of restriction. With preinstalled operating system you can do what you want and if you can find a way to change it for that. You know very well that there are hundreds of different players in the market. You can't wait for Toshiba take a time and create a plugins for each other and satisfy customers around the world.

  • How to use the product with laptop Portege R150 recovery CD?

    How to use the recovery CD product with laptop Portege R150 of Formate and reinstall the operating system?

    Mobile recovery procedure Asian does not for me but may not be very different as on mobile phones produced in Europe or the United States.

    Start your laptop and press F12 to display the boot options
    Place the recovery disc into the optical disc drive
    In the start menu, choose the CD/DVD drive and press ENTER
    The procedure of the facilities is expected to begin
    Follow the menu on the screen

    I do not know what will be shown at this stage, but it is not complicated to install the original recovery image. If you have any other questions please let me know what happens when upgraders begins. What options are displayed?

  • How to use WVC54GCA webcam with Skype?

    I just installed the wirelesss WVC54GCA webcam. The wireless part works very well in the House, but I don't know how to use it on the internet. How can I make my default webcam for Skype? Do I need additional Windows drivers?

    WEBCAMXP there WDM drivers that allow you to use the camera WVC54GCA with Skype. They are free to download. Thanks for the link!

  • How to use Data Guard with E-Business Suite

    Hello

    I'm trying to get my head around how would you use Data Guard with E - Business Suite.

    I know that you can use only physical standby with EBS, however I have a few basic questions about specific values < SETTING > and how they are treated by a standby.

    Given that the standby and primary servers will have different host names and that generally there are < FRAME > specific values that include the hostname, where they will have to change on the standby server, both from the point of view of the battery backup Apps and within the standby database itself, I wondered how it would happen.

    Usually, EBS cloning process would change the < FRAME > target settings in the target apps stack and the target database (for example, parameters such as FND_NODES etc.).

    Q1. However I do not know how the process of cloning E - Biz would fit with a database of the day before?

    Q2. As the standby database won't even be in an open State, I don't know yet how you would apply a party any of the cloning process to a database of pending to the target?

    Q3. Even if you were able to change on the eve of the database to reflect the < FRAME > from backup server, it would mean surely it was more a physical copy of the primary database, that's why it would be more a day before.

    All a bit confusing - any clarification appreciated

    Jim

    PL see if MOS Doc 1070033.1 can help you

  • How to use the date with the report parameter format

    Hi all

    How to use the date format with this tag function,

    <? param@begin:P_FROM_DATE? > <? $P_FROM_DATE? >

    This date of form source of report and setting is coming as this 2012/11/01 00:00:00.

    So now I need this in MY-DD-YYYY marker. I tried like this..? param@begin:P_FROM_DATE? > <? $format - date: P_FROM_DATE; ' DD-MON-YYYY '? >

    but its giving error. Can someone pls how to convert to the format of date custom.

    Thanks and greetings
    Srikkanth.M

    Problem solved.

    REF this link

    Date Format of XML

  • How to use the import with FDM with adapter ERPI script?

    Hello

    I use FDM and ERPI 11.1.2 to load data of EBS R12 to planning 11.1.2

    Loaded from eBS data for a YEAR.

    I realized I could use an import script to manually calculate the amount with the periodic_net_cr and periodic_net_dr fields.

    But how to use this import script? Because in my import in FDM format, I do not use a file but directly the adapter, if no field "Expression".

    Thanks in advance for your help

    Fanny

    You must use the ImportAction script.

  • How to use a list in a query so that you can sort the list according to an attached table?

    1. my initial query returns the phone numbers with inconsistent structures. Example:

    -555 (555) - 5678

    666-555-5678.

    555.5678 (444)

    1-888-555-5678

    2. I have to loop through the list and perform a certain number of cleaning functions, this is why the list looks like this:

    555-555-5678.

    666-555-5678.

    444-555-5678.

    888-555-5678.

    3. now, I need to use this list in a query, if I can use the first three digits to seek a regional indicative table sign and its link and be able to sort by area code. The indicative table looks like this:

    ThreeDigitCode AreaID

    555                         1

    666                         2

    444                         1

    888                         4

    I need to put the phone in the query list, so I can do a search of the areaID and the comparable information to a table that says AreaID 1 is Eastern and his sort-position is 1, etc..

    Thanks in advance for your advice.

    You can add an empty your query column, when you select the phone

    numbers and use this column to store the ThreeDigitCode:

    SELECT phone_number, '' as threeDigitCode FROM #your_table#
    

    then clean up the numbers and place the 3 digits in others

    column. And then using query of query to join phone numbers with

    area codes:

    
      
    
    
    
      SELECT *
      FROM phone_number
        INNER JOIN area_codes ON area_codes.threeDigitCode =
    phone_number.threeDigitCode
    
    

    Mack

  • How to use HorizontalList filled with an array of an Image?

    Is it possible to fill a HorizontalList with an array of an Image? I am trying to create a HorizontaList of Images (thumbnails) by using a dynamic method where I put each thumbnails found in a table and then indicate the HorizontalList to use the array as the dataProvider. The result is that I just saw the ID generated for each Image.

    Since I'm controlling the content of the HorizontalList in the mx:source, I'm a bit confused how to use the itemRenderer property.

    Any help will be appreciated since Google doesn't show a lot of example/problems like mine at the moment!

    Hello

    Fair value the itemRenderer property mx.controls.Image and you should do.

Maybe you are looking for