11g: should i use SQL connect by?

DB: 11.2.0.2.0
Apex: 4.2.1.00.08
Hi there,
I'm using Apex but this is a fairly basic SQL question, hence posting here.
I have two tables, one containing staff details (one row per staff member) and the other containing team structure (team_id, team_name, parent_id).
STAFF:
1--Fred Bloggs--TeamID21 
2--John Doe--TeamID35
TEAMS:
21--TeamOne--17
35--TeamTwo--17
17--TeamThree--4
4--TeamFour--NULL
It is possible for there to be an unlimited number of sub-teams with this structure, although in practice there is almost always just a business unit > division > department > team.
I'm trying to pull out teams and parents to display as columns against staff names, e.g.:
1--Fred Bloggs--21--TeamOne--17--TeamThree--4--TeamFour
2--John Doe--35--TeamTwo--17--TeamThree--4--TeamFour
The purpose in Apex terminology is to populate a "superLOV" so that users can select between 3,000 staff more easily by seeing which departments they are in.
I also want to filter the list for one division at present, just showing departments and teams below that (I assume I use START WITH although have not succeeded yet).
Is it possible to do what I want, given that for some teams there might be two sub-teams below division, and for others there might be four? And should I just use four JOINS rather than CONNECT?
My SQL so far is variations on this theme:
SELECT
s.staff_id as "ID",
t.TEAM_NAME as "Team name",
s.staff_lastname|| ', ' || s.staff_firstname as "Name"
FROM AA_WL_STAFF2 s
JOIN AA_WL_TEAMS3 t
ON t.TEAM_ID=s.STAFF_TEAM
CONNECT BY t.PARENT_ID=t.TEAM_ID
ORDER BY s.STAFF_LASTNAME || s.STAFF_FIRSTNAME ASC
One problem with this is that I can't then pull out PARENT TEAM_NAME without re-joining. Also START WITH t.PARENT_ID=4147 (the division's TEAM_ID) just returns staff working directly for the division's director, rather than all staff in all teams under him.
Grateful for any pointers
Emma

Hi,
You should separately create the team tree, and then join with the staff.
Also use PRIOR operator (CONNECT BY PRIOR team_id = parent_id).

Similar Messages

  • HT201300 What cable should be used to connect a macbook pro, 13 inch early 2011 model to an external projector so it will display the computer screen image through the projector?

    What cable should be used to connect a macbook pro, 13 inch, early 2011 model to an external projector so the project displays the image on the computer screen?

    You will need a cable or adapter with a minidisplay connection for the MBP.  That will be inserted in the Thunderbolt port.  The other end is dependent upon the connections of the projector which you have not listed.
    Ciao.

  • 11g: can connet using SQL*PLUS, not with TOAD

    Hi
    I run into a problem with TOAD. I can't connect with my 11g database using TOAD. I don't get any messages it just gives me a little waiticon for a split second and then nothing happens. I can however connect to my 10g database using TOAD. Using SQL*Plus I can connect to both.
    I use TOAD 8.6. Do I need a newer version maybe??...

    I can connect like:
    hr/pw@xe
    or
    hr/pw@O11R1
    or directly, no problem. I can connect from SQLplus to both databases any way I want

  • What cable should I use to connect an old iBook G4 to a MacBook Pro in order to transfer files?

    I'd like to transfer files from the iBook G4 to my new MacBook Pro.  However, I'm not a "pro" at using a computer and I'm not even sure what cable to use to connect the two laptops.  I welcome your suggestions!

    The Y is FireWire and the MBP has a FW800 port. On the iBook you should find a FW400 port shaped like an arrow (see below, left pic). So for speediest transfer, you need a Firewire 400 to Firewire800 cable that will allow you to plug both Macs together (right pic).
    Once you have gotten that, place the IBook in Target Disk Mode (see here: http://support.apple.com/kb/HT1661 ) and connect both with the cable. The iBook's hard disk drive will appear on the MacBook's desktop. You can either drag stuff across or use the Migration Assistant found in Utilities to ensure applications get transferred correctly.

  • What is the connection method should i use to connect database to visual basic?

    i'm confusing about that, what is ADO.Net, Entity Framework, LINQ to Entities and LINQ to SQL
    what i should learn to connect my database in SQL to visual basic?

    Hello Galeluo,
    >>i'm confusing about that, what is ADO.Net, Entity Framework, LINQ to Entities and LINQ to SQL
    There are documents for these concepts:
    ADO.Net:
    https://msdn.microsoft.com/en-us/library/e80y5yhx%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396
    Entity Framework:
    https://msdn.microsoft.com/en-us/library/vstudio/bb399567(v=vs.100).aspx
    LINQ to Entities:
    https://msdn.microsoft.com/en-us/library/vstudio/bb386964(v=vs.100).aspx
    LINQ to SQL:
    https://msdn.microsoft.com/en-us/library/bb386976(v=vs.110).aspx
    In above links, we can see that all are approaches which could be used to access database except the LINQ to Entities which is a query approach and is based on Entity Framework.
    >>what i should learn to connect my database in SQL to visual basic?
    If you are starting to use the .NET api to connect a database, I suggest you could use the ADO.NET api which is a underlying api, both Entity Framework and LINQ to SQL are based on this one.
    Regards.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Utils is a packege then should i use sql function in place of utils.

    Hi,
    while translating my sp from mssql to oracle few code is converted into : utils
    utils is a package i think so is it good to use it or should i find any sql equivenlent function.
    then please tel me oracle sql function for utils.patindex();
    yours sincerely

    Please bear in mind that most people here know Oracle but not SQL Server. So if you wish to use us as a translation service it would be helpful if you told us what the SQL Server function does.
    Googling for [url http://msdn.microsoft.com/en-US/library/ms188395(v=sql.90).aspx]PATINDEX() reveals that it is a function which returns the position of a pattern in a string. --The Oracle equivalent is INSTR().  [url http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions080.htm#sthref1174]Find out more.--
    Just to prove the point I now think INSTR() is the equivalent of CHARINDEX and what you actually want is one of the regex functions such as REGEXP_INSTR() [url http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions148.htm#sthref1419]Check it out.
    Oh, and please, don't use us as a translation service. Read the Oracle documentation or [url http://www.google.co.uk/#q=ms+sql+patindex+oracle&oq=ms+sql+patindex+oracle]use Google.
    Cheers, APC
    Edited by: APC on Feb 28, 2013 6:10 AM

  • MOSS 2007 Database Migration using SQL connection alias change throwing error

    Hi Folks,
    We are trying to move SharePoint SQL server from one DC to another DC.
    Since we have made SQL server in new DC with other name so opted SQL server connection alias method to remap SQL mapping with existing farm.
    After creating SQL alias we are able to browse central admin sites but could not able to browse any other sharepoint sites.
    Event viewer showing below exception
    SQL database login failed. Additional error information from SQL Server is included below.
    Login failed for user 'computername$'.
    Any view will be much appreciable.
    Regards

    First: Putting SQL Server on a domain controller is not recommended. 
    Are the two domain controllers in different domains? Is the SharePoint server in the same domain as the new SQL instance?
    Do you have a SharePoint farm or a standalone installation? A
    common cause of the error you're seeing is if the application pools are using Network Service or Local System which can be the case of a standalone installation.
    Jason Warren
    @jaspnwarren
    jasonwarren.ca
    habaneroconsulting.com/Insights

  • What connection should I use to connect my laptop to a Toshiba tv

    It's an XV model - please help!

    Yes, that is just an adapter to enable you to use the HDMI lead, you will also need to connect the sound separately, that will depend on the connections your TV has, something like this http://www.amazon.com/PH62089-Stereo-Mini-Male-RCA-Male-Feet/dp/B0001GAOE0
    You can compare the different connectors here http://store.apple.com/uk/browse/home/shopmac/macaccessories/cables?mco=MTM3NTI2OTg
    Message was edited by: kdb1

  • What cable should I use to connect my g4 to a 19'flat screen hd  tv?

    Whats it called?
    Is it widely available?
    Want to watch DVD and maybe use it as a second monitor
    Thanks!
    Marc

    Your Powerbook has a DVI video-out port, and the best video quality will be obtained by connecting that port to the HDMI port on your television, using an adapter cable with the appropriate male/female ends. Google "DVI to HDMI adapter" to find suppliers online, or go to your local electronics big-box store (take your Powerbook along) and find one there. Note that DVI and HDMI cables don't carry audio, so you'll need to cable the audio from the Powerbook to the TV set separately.

  • What driver should I use to connect my GPIB-SCSI-A box on a Win2000 PC ?

    Win2000 recognise my GPIB-SCSI-A box when I startup my PC but I can't find any driver to make LabVIEW and MAX recognise it. Previously, I was using my GPIB-SCSI-A box on a Macintosh.
    Please tell me where to find that driver for Win2000 (if any exist).

    Francois,
    Unfortunately, National Instruments does not have a supported driver for the GPIB-SCSI-A board in any environment other than MAC.
    Ryan Mosley
    National Instruments, Applications Engineer
    http://www.ni.com/exchange

  • SQL Connection object

    Hi,
    Is there any issue(or problem) if we use SQLConnection object and communicate to SQL server instead of using business object or business query.
    thanks and regds
    harish

    Hi Kai/Pratik Patel
    Thanks for replying. One more question in this regard. Where to store the connection string if you are going to use SQL Connection object, so that we have to create the connection string only once.
    As in other .NET application (Windows and Web) we store it in the configuration file but in the MSA we do not have configuration file.
    Thanks and Regds
    Harish

  • Unable to connect to a remote db using Sql Developer

    hi,
    I have 2 systems (A and B) both running on RHEL 6. A has Oracle 10G installed while B has Oracle 11G, and on both I have SQL Developer. A and B are cable networked with static IPs as below.
    A 192.168.1.1
    B 192.168.1.2
    I am trying to connect to database on A from SQL Developer on B. On B, I open SQL developer, enter the connection name, username, password, hostname( or IP) of A, port #, and instance name and hit connect. It shows error about network adapter. I cannot connect.
    Listners on both system are active, I can ping each system from each other. No issues with /etc/hosts either.
    I am not sure then why it does not work. Would like to know if I can / should be able to connect like above ? What else should I look at to fix?
    Shashi

    Hello Sir,
    Can you telnet to the server on 1521? (telnet A 1521)- failed. with no route error
    However, I could telnet B from A without any prob. I then came across a workaround at
    TNS-12560: TNS:protocol adapter error
    which suggests to :
    Go into the Security Level Configuration on your Linux server. In Other Ports, specifically enter <port>:tcp, (example 1521:tcp.
    and it worked :)
    I am still not sure, why I had to take the workaround route when there was no difference between 2 systems, in terms of route tables, host file entries, sqlnet.ora,listner.ora, etc . I am glad that the issue is resolved and I am able to connect from SQL Developer on A to db on B and other way round, but the the question still remains... :)

  • Problem in connecting Database by using SQL Developer

    Hi,
    I recently installed SQL Developer after installing Oracle 10g and am trying to connect existing database. could anybody help me to connect and what credential should i required to connect.
    Thanks in advance
    LN Reddy

    I am new to oracle myself, so I apologize if this information is not helpful. But I have a number of connections to a local database on my laptop. The way that I connected is using the 'Basic' tab with the following settings:
    Hostname: localhost
    Port: 1521
    SID: orcl
    And of course the username above.
    I hope that might be helpful.

  • Should I use BCS my backend database will update all the record of the sql table daily.

    Should I use the BCS where the database table is going to be updated daily.
    All the records will be updated on daily basis.
    Why should I use BCS when I can connect to the sql server directly and  update the records that I need.
    What additional benefits can I get from BCS , I do not need the search functionality.
    Regards

    Hi,
    According to description, my understanding is that you want to know if you need to use Business Connectivity Services to connect external SQL table.
    Business Connectivity Services is a centralized infrastructure in SharePoint 2013 and Office 2013 that supports integrated data solutions.
    Business Connectivity Service will provide a familiar user interface to manage sql table data. It is more security for reading and writing data to external sql table.
    Here is a detailed article for your reference:
    https://technet.microsoft.com/en-us/library/ee661740(v=office.15).aspx
    https://msdn.microsoft.com/en-us/library/office/ee556440(v=office.14).aspx
    Best Regards
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
    [email protected]
    Jerry Guo
    TechNet Community Support

  • SQL - Database access using Oracle.connect(getCLass(), "connect.properties")..IM LOST

    Hi,
    I use Oracle.connect(getClass(),"connect.properties") before all of my #sql statements. If there are a bunch of methods with #sql statements, I use the connection method. I think this is my problem and Id like some feedback from other people.
    1) Should i be using an Oracle.connect statement before every #sql?
    2) If so, does it create new connections all the time or does it just know there is a current connection so it doesnt keep adding new connections?
    3) Is there a way to get one connection and then test to see if there is a connection so that i dont keep getting new connections?
    4) Do I have to close the connections? I tried Oracle.close(); but got some wierd errors. I read somewhere that If autocommit is true, you dont have to close jdbc connections.
    Thanks for your time and I appreciate any feedback that anyone has to offer.

    Hi Adam,
    Please find the answers inline.
    I use Oracle.connect(getClass(),"connect.properties") before all of my #sql statements. If there are a bunch of methods with #sql statements, I use the connection method. I think this is my problem and Id like some feedback from other people.
    1) Should i be using an Oracle.connect statement before every #sql?No, you don't have to call this each time, just call this once to intialize your DefaultContext and from then on, whenever
    #sql is used, it would fetch the connection from the DefaultContext.
    2) If so, does it create new connections all the time or does it just know there is a current connection so it doesnt keep adding new connections?No, it doesn't create connections each time.
    3) Is there a way to get one connection and then test to see if there is a connection so that i dont keep getting new connections?There would be only one connection
    4) Do I have to close the connections? I tried Oracle.close(); but got some wierd errors. I read somewhere that If autocommit is true, you dont have to close jdbc connections.The connection has to be closed explicitly using Oracle.close();
    For samples on using connect.properties refer to,
    http://otn.oracle.com/sample_code/tech/java/sqlj_jdbc/files/9i_sqlj/9i_sqlj.html#BatchingAndREFCursorSample
    Regards
    Elango.

Maybe you are looking for

  • Playback Buttons and Thumbnails

    Hello Everyone and thanks fo ryour help in advance.  I am completely new to Flash and am just trying to get some of the basics correct.  I would like to create a Flash movie.  At the heart of my question is how to create a preview type of display on

  • In Develop, the "reset" button does not take me back to the original photo?

    When I click "reset" my photos do NOT return to the original photo. New MacBookPro computer. what is wrong. On my Dell computer I can reset the photo not losing any data.

  • Using variables in a java.properties file

    Hi, I have a .properties file that I'm using to configure an app. I was wondering if there is a way to set a property = to an already defined property and more. So for example: app.siteroot=c:\tomcat\webapps\myapp app.templatefolder= app.siteroot + \

  • Using "Tech Tool Deluxe" In Leopard

    My MacBook Pro came with Tiger and the Apple included CD Tech Tool Deluxe. On running Tech Tool Deluxe under Tiger, my MBP passed all tests. I updated to Leopard. I downloaded the update for Leopard from Tech Tool. Now my MBP fails the video ram test

  • QX 10 – optimised for the new Mac Pro?

    I recently upgraded to a new Mac Pro. So am now considering going back to QX (I am a pro graphic designer). They have a deal offering special pricing for upgrades from version 3 (AUD $399)! Question: Is QX 10 optimized for the new Mac Pro? Any design