Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi all! We have been experiencing an issue on site where threads have been missing the latest postings. The platform host Vanilla are working on this issue. A workaround that has been used by some is to navigate back from 1 to 10+ pages to re-sync the thread and this will then show the latest posts. Thanks, Mike.
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

SQL query help

  • 11-08-2006 9:11am
    #1
    Registered Users, Registered Users 2 Posts: 23,212 ✭✭✭✭


    It's scary how much SQL I have forgotten since I haven't been using it in so long. I'm struggling with the following scenario (Oracle).

    I have a table that has a status field and an ID (among others). So I do a SELECT ID, STATUS from TABLE and I get data such as the following:

    ID Status
    123
    124
    125 5
    126
    127 9

    If the status is null, I use a decode to return a value of Active. So I get

    ID Status
    123 Active
    124 Active
    125 5

    Now here's the part I am struggling with.

    If status returns a value (see above) I need to join these with another table to lookup the status code and return the status. So I need either the decode or the lookup returned, but obviously not both.

    I would really appreciate any insights to this.


Comments

  • Registered Users, Registered Users 2 Posts: 2,758 ✭✭✭Peace


    Probably wrong but here:
    SELECT TABLE1.ID, TABLE1.STATUS, TABLE2.STAUS_DETAIL FROM TABLE1
    INNER JOIN TABLE2 ON TABLE1.STATUS = TABLE2.STATUS_DETAIL
    

    You should look at INNER JOIN. Isn't there a query designer in ORACLE? THere is in SQL Server and i rustle up those sort of queries in seconds without even turning my brain on, it does the work for me.


  • Registered Users, Registered Users 2 Posts: 23,212 ✭✭✭✭Tom Dunne


    Doesn't work, I'm afraid.

    That excludes the rows where the status is Null (i.e. the one which I use the decode on, so I don't get any status of Active).

    Oracle has loads of tools, but for the most part, you have to buy them. We don't have query designer here, unfortunately.


    Edit: Got it working. Here's the code for anyone interested:

    select t1.id, decode(t2.status,'','Active',t2.status)
    from table1 t1, table2 t2
    where t1.status=t2.status(+)


  • Registered Users, Registered Users 2 Posts: 2,781 ✭✭✭amen


    gald you got it working.
    You wanted to look at OUTER JOINS not Inner joins

    what the (+) syntax? Looks like Oracle specific not ANSI standard


  • Registered Users, Registered Users 2 Posts: 23,212 ✭✭✭✭Tom Dunne


    Yeah, the (+) in this case is an outer join.

    More details from Oracle's documentation here.


Advertisement