SELECT - INNER JOIN / multi-table question

I have a few pages where I can:
register a new user
Open as this user which brings me to a home page. from there I can go to 'my page' users where I can see their fine of the initial registry data. I have a link here where I can go to add to their additional profile data that I didn't want to bore in the original registration.

It perfect all worked with the original test data, I've created in the database.

After that I added the additional tables needed to feed the profile further I ran into trouble. I could create a new user, see in the database is fine. I see them on the homepage with their information through the Recordset. However when I'd go to their 'my page' none of their information would be fill and go to extra profile update page haven't fired a no records found message.

Finally, I realized that the reason for this is because the SELECT statement is waiting for the other tables to fill. I filled in the missing data and the query to work. So... Now that I know what is causing the problem I need help to find a solution. Also, I'm still new to find work around me even after 4 days of research and reading messages.

So when a new user registers, I need to be able to display data from the initial registration on the "my page" and get their user_id for profile tables add somehow so that when I go to the add profile page, there is a link.

I don't know if I need to do something in the database or in my query. It there any sense to anyone? I need to create the user_id on other tables during registration of origin occurs? If so, how would I go all this?

Thanks in advance. My INNER JOIN is attached in case it helps.

I have a few pages where I can:
register a new user
Open as this user which brings me to a home page. from there I can go to 'my page' users where I can see their fine of the initial registry data. I have a link here where I can go to add to their additional profile data that I didn't want to bore in the original registration.

It perfect all worked with the original test data, I've created in the database.

After that I added the additional tables needed to feed the profile further I ran into trouble. I could create a new user, see in the database is fine. I see them on the homepage with their information through the Recordset. However when I'd go to their 'my page' none of their information would be fill and go to extra profile update page haven't fired a no records found message.

Finally, I realized that the reason for this is because the SELECT statement is waiting for the other tables to fill. I filled in the missing data and the query to work. So... Now that I know what is causing the problem I need help to find a solution. Also, I'm still new to find work around me even after 4 days of research and reading messages.

So when a new user registers, I need to be able to display data from the initial registration on the "my page" and get their user_id for profile tables add somehow so that when I go to the add profile page, there is a link.

I don't know if I need to do something in the database or in my query. It there any sense to anyone? I need to create the user_id on other tables during registration of origin occurs? If so, how would I go all this?

Thanks in advance. My INNER JOIN is attached in case it helps.

Tags: Dreamweaver

Similar Questions

  • Change of shape joining multi tables SQL...

    I need to be able to join the tables in the detail section of my master-detail form. Since I have more than three paintings to join, I think that APEX needs to use "ROWID" to track the value of the key of the primary table. When I try substitute basic sql generated for the report to my own joined table I get an error return "IMPOSSIBLE of ANALYSER. If I remove "ROWID" in the statement, then fine. Here's the statement from the apex generated:

    Select
    "ROWID",.
    "PO_ID."
    "PO_DET_ID,"
    "CHANGE_ORDER,"
    'START_DATE ',.
    'END_DATE ',.
    "PO_DET_AMT,"
    "SCOPE."
    "PO_STATUS,"
    "MRS."
    of ' #OWNER # '. " PO_DETAILS ".
    where "PO_ID" =: P240_PO_ID

    However, I need for the statement as follows:

    Select "ROWID",.
    po_details.po_id,
    po_details.po_det_id,
    po_details.change_order,
    po_details.start_date,
    po_details.end_date,
    po_details.po_det_amt,
    po_details. Scope,
    po_details.po_status,
    po_details. WBS
    of PO_DETAILS, IN., WBS, PROJECT
    where po_details.po_id = po.po_id
    and po.po_number = wbs.po_number_id
    and po_details.wbs = wbs.wbs_number_id
    and substr (wbs.wbs_number_id, 1, 6) = project.wbs_sequence
    and project.project_number = nvl(:F101_FPC_NUMBER,project.project_number)
    and po_details.po_id =: P240_PO_ID

    Then, I get the following ORACLE error:

    •Query cannot be parsed in the generator. If you believe that your query is syntactically correct, check the generic "columns" box below the source of the region without analysis. ORA-00918: column ambiguously defined

    I'm guessing that the column "defined ambiguous ' is ROWID.

    SELECT the query aspect works fine if I remove ROWID, but I then cannot update the table when the user needs to change the data. I get an exception defined by the user.

    I am new to APEX, so I do not know there are certain aspects that I'm missing.
    Any tips?

    There is no way to use a join of multiple tables in the APEX?

    Of course you can. Have you tried again (with the help of PO_DETAILS ROWID in the select statement)?

    I tried with a form on EMP and then modified the query to:

    select
    e."ROWID",
    e."EMPNO",
    e."ENAME",
    e."JOB"
    from "#OWNER#"."EMP" e, dept d
    where e.deptno = d.deptno
    and d.deptno = :P14_DEPTNO
    

    IMHO, it's simply more transparent if you use a view as the source. You select a view, and you update the same point of view.

    Published by: InoL on May 14, 2013 13:49

  • Retrieve all records in the selected master child multi tables

    Hello
    I use JDeveloper 11.1.1.4 version and using ADF - BC in my project.
    I have a one-to-one simple child master [several] in my project.
    In my view page, I display this master child [Ex: EmpVo1-> DeptVo2] in the form of tables.

    I have multi-selection enabled for the main table.
    My requirement is that, on the multi by selecting the lines in the main tables, I want to get all the child records in my grain of support.
    If a master has 3 child records line and another main line has 4 child records and on the selection of several of these two records in the primary table, I should get all the child records in my grain of support.
    I need it to implement the cascade delete feature.
    Here is the sample code coin
    --------------------------------------------

    (1) called on selecting rows in the master table

    {} public void onRSCGrpSelect (SelectionEvent selectionEvent)
    Add the code in the event here...
    ADFUtil.invokeEL ("#{bindings.") RscGroupVO1.collectionModel.makeCurrent} «»
    new class [] {SelectionEvent.class},
    (New Object() {selectionEvent});

    RowKeySet rowKeySet = (RowKeySet) tblRSCGrp.getSelectedRowKeys ();
    CollectionModel cm = (CollectionModel) tblRSCGrp.getValue ();

    for (object facesTreeRowKey: rowKeySet) {}
    cm.setRowKey (facesTreeRowKey);
    RowData = JUCtrlHierNodeBinding
    (JUCtrlHierNodeBinding) cm.getRowData ();
    Line = rowData.getRow ();
    System.out.println ("\n" +)
    row.getAttribute (0) + ":" + row.getAttribute (1) +.
    (":" + row.getAttribute (2));

    System.out.println ("display the child records");
    displayChildRecords (row.getAttribute (0));

    }

    }

    2 private void displayChildRecords (Object rscGrp) {}
    ViewObject rscMapVo = getRscMapViewObj();
    RowSetIterator rsI = rscMapVo.createRowSetIterator (null);
    While (rsI.hasNext ()) {}
    Line = rsI.next ();
    System.out.println ("\n" +)
    row.getAttribute (0) + ":" + row.getAttribute (1) +.
    (":" + row.getAttribute (2));
    }
    rsI.closeRowSetIterator ();
    }

    But the problem is that he is always giving me the last selected lines child details.

    Please suggest the error that I do.

    Thank you
    Praveen

    Your problem is to use makecurrent, which should not be used on a multi selection table. Then, if you have a relationship master detail you should have a view link between them. In this case, you can expose a method as you master to get the related child line. Not need to get the VO itself you can use the accessors of child iterator to obtain registration of the child.

    public void onRSCGrpSelect(SelectionEvent selectionEvent) {
    // Add event code here...
    RowKeySet rowKeySet = (RowKeySet)tblRSCGrp.getSelectedRowKeys();
    CollectionModel cm = (CollectionModel)tblRSCGrp.getValue();
    
    for (Object facesTreeRowKey : rowKeySet) {
    cm.setRowKey(facesTreeRowKey);
    JUCtrlHierNodeBinding rowData =
    (JUCtrlHierNodeBinding)cm.getRowData();
    Row row = rowData.getRow();
    //cast to the right row class
    EmpEmpVoRow empRow = (EmpEmpVoRow) row;
    // now you cann access the child row iterator
    RowSetIterator it = empRow.getDepVO();
    //now you cna iterate over the child rows
    System.out.println("\n" +
    row.getAttribute(0) + " :: " + row.getAttribute(1) +
    " :: " + row.getAttribute(2));
    
    System.out.println("Displaying Child Records");
    //use hte child rows here
    
    }
    
    }
    

    Don't know if the code compiles out of the box (do this on the train :-)

    Timo

  • JOIN the question... Join two tables without omitting lines

    I came across a problem that should be an easy fix (I hope), but I'm having a hard time to come up with a solution.

    Basically I have two tables, one with the actual amounts with the budget. I have to write a sql statement select that joins these tables together and includes all of their lines. I was able to join the tables by using JOIN, LEFT JOIN and RIGHT JOIN, but it always fails the lines I need.

    Below, I have examples of my tables (AMOUNT_TABLE and BUDGET_TABLE). For simplicity, I built the examples to show the same values in the first four columns, with the 5th and 6th columns (SUB_ACCOUNT, AMOUNT, BUDGET) as the only values that are different. My actual tables are not quite that simple, but I don't think it was relavent to this issue.

    AMOUNT_TABLE

    FISCAL_YEAR PERIOD ACCT_UNIT ACCOUNT SUB_ACCOUNT AMOUNT

    2013

    111111555555000010020131111115555551000100201311111155555520001002013111111555555300010020131111115555554000100

    BUDGET_TABLE

    FISCAL_YEAR PERIOD ACCT_UNIT ACCOUNT SUB_ACCOUNT BUDGET

    2013

    1111115555553000200201311111155555540002002013111111555555500020020131111115555556000200

    Here's what I hope. Note that SUB_ACCOUNTs 0000, 1000, and 2000 show without budget amounts since there is not a corresponding line in the BUDGET_TABLE. And same for SUB_ACCOUNTs 5000 and 6000, they show budgets with no amount because there is not a corresponding line in the AMOUNT_TABLE.

    (exit)

    FISCAL_YEAR PERIOD ACCT_UNIT ACCOUNT SUB_ACCOUNT AMOUNT BUDGET
    201311111155555500001000
    201311111155555510001000
    201311111155555520001000
    20131111115555553000100200
    20131111115555554000100200
    201311111155555550000200
    201311111155555560000200

    If all goes well, my question is clear. Any help on this would be greatly appreciated. Thanks in advance.

    Use the join ANSI - FULL OUTER JOIN syntax:

    with amount_table like)

    Select fiscal_year 2013, 1 period, 11111 acct_unit, 555555, 0000 sub_account, amount 100 of all the double union

    Select 2013,1,11111,555555,1000,100 from all the double union

    Select 2013,1,11111,555555,2000,100 from all the double union

    Select 2013,1,11111,555555,3000,100 from all the double union

    Select double 2013,1,11111,555555,4000,100

    ),

    budget_table like)

    Select 1 time, 11111 acct_unit, account 555555, sub_account 3000, 2013 fiscal_year, budget of 200 Union double all the

    Select 2013,1,11111,555555,4000,200 from all the double union

    Select 2013,1,11111,555555,5000,200 from all the double union

    Select double 2013,1,11111,555555,6000,200

    )

    Select nvl (a.fiscal_year, b.fiscal_year) fiscal_year,

    period of NVL (a.period, b.period),

    NVL (a.acct_unit, b.acct_unit) acct_unit.

    account of NVL (a.Account, b.Account),

    NVL (a.sub_account, b.sub_account) sub_account.

    Amount NVL(a.amount,0),

    NVL(b.budget,0) budget

    of amount_table one

    full join

    budget_table b

    on)

    a.Fiscal_Year = b.fiscal_year

    and

    a.period = b.period

    and

    a.acct_unit = b.acct_unit

    and

    a.Account = b.account

    and

    a.sub_account = b.sub_account

    )

    /

    FISCAL_YEAR PERIOD ACCT_UNIT ACCOUNT SUB_ACCOUNT AMOUNT BUDGET
    ----------- ---------- ---------- ---------- ----------- ---------- ----------
    2013 1 11111 555555 0 100 0
    2013 1 11111 555555 1000 100 0
    2013 1 11111 555555 2000 100 0
    2013 1 11111 555555 3000 100 200
    2013 1 11111 555555 4000 100 200
    2013 1 11111 555555 6000 0 200
    2013 1 11111 555555 5000 0 200

    7 selected lines.

    SQL >

    SY.

  • Outer join complete Multi Table

    What is the syntax to make a full outer join on three tables. All the examples I can find use using the clause, but in my case, the column names are not the same in the three tables

    Hello

    Use IT instead of USE.

    Assuming that all the 3 tables will have a common value in a column (whatever it is called):

    ...
    FROM           table_x  x
    FULL OUTER JOIN      table_y  y     ON     y.idy     = x.idx
    FULL OUTER JOIN      table_z  z     ON     z.idz     = COALESCE (x.idx, y.idy)
    

    When comes the time to join table_z, you won't know which of the previous tables match, so you must use COALESCE to try them all.

    If you need to join several tables in this way, the expression of COALESCE for the nth table will have (n - 1) arguments.

  • difference between Inner Join join natural r

    Experts,

    I'm trying to understand the difference between Natural Join and inner join.

    Inner join: the following query provides 106 lines based on two tables

    SQL > SELECT EMPLOYEE_ID EID, last NAME, DEPT_NAME DEPARTMENT_NAME

    2 EMPLOYEES A, B MINISTRIES

    3. WHERE A.DEPARTMENT_ID = B.DEPARTMENT_ID

    4 order employee_id;

    Natural Join: This is the combination or combined result of all the columns in both tables.

    When I run the Sub statement, it combines employees and the table from department of a HR schema and provides only 32 ranks

    SQL > select employe_id, first_name, department_name

    2 departments of NATURAL JOIN employees;


    EMPLOYEE_ID NAME DEPARTMENT_NAME

    ----------- -------------------- -------------------

    Neena 101 Executive

    Lex 102 Executive

    104 Bruce IT

    David 105 HE

    question: why the NATURAL JOIN query omit the employee_id 103 and on what basis it omit a few other employee_id

    Thanks in advance

    Hello

    The main difference is that INNER JOIN is used in real life; NATURAL JOIN is used only in textbooks.

    More rigorously, FRANCKLIN JOIN is an inner join, involving all the columns that have the same name.  The hr.departments and hr.employees have 2 columns with the same name: department_id and manager_id, so

    OF hr.departments d

    NATURAL JOIN e hr.employees

    is equivalent to

    OF hr.departments d

    INNER JOIN hr.employees e ON e.department_id = d.deparment_id

    AND e.manager_id = d.manager_id

    or, using the old join syntax

    OF hr.departments d

    e hr.employees

    WHERE e.department_id = d.deparment_id

    AND e.manager_id = d.manager_id

  • date max with multiple joins of tables

    Looking for expert advice on the use of max (date) with multiple joins of tables. Several people have tried (and failed) - HELP Please!

    The goal is to retrieve the most current joined line of NBRJOBS_EFFECTIVE_DATE for each unique NBRJOBS_PIDM. There are several lines by PIDM with various EFFECTIVE_DATEs. The following SQL returns about 1/3 of the files and there are also some multiples.

    The keys are PIDM, POSN and suff

    Select NBRJOBS. NBRJOBS.*,
    NBRBJOB. NBRBJOB.*
    of POSNCTL. Inner join of NBRBJOB NBRBJOB POSNCTL. NBRJOBS NBRJOBS on (NBRBJOB. NBRBJOB_PIDM = NBRJOBS. NBRJOBS_PIDM) and (NBRBJOB. NBRBJOB_POSN = NBRJOBS. NBRJOBS_POSN) and (NBRBJOB. NBRBJOB_SUFF = NBRJOBS. NBRJOBS_SUFF)
    where NBRJOBS. NBRJOBS_SUFF <>'LS '.
    and NBRBJOB. NBRBJOB_CONTRACT_TYPE = 'P '.
    and NBRJOBS. NBRJOBS_EFFECTIVE_DATE =
    (select Max (NBRJOBS1. NBRJOBS_EFFECTIVE_DATE) as 'EffectDate '.
    of POSNCTL. NBRJOBS NBRJOBS1
    where NBRJOBS1. NBRJOBS_PIDM = NBRJOBS. NBRJOBS_PIDM
    and NBRJOBS1. NBRJOBS_POSN = NBRJOBS. NBRJOBS_POSN
    and NBRJOBS1. NBRJOBS_SUFF = NBRJOBS. NBRJOBS_SUFF
    and NBRJOBS1. NBRJOBS_SUFF <>'LS '.
    and NBRJOBS1. NBRJOBS_EFFECTIVE_DATE < = to_date('2011/11/15','yy/mm/dd'))
    order of NBRJOBS. NBRJOBS_PIDM

    Welcome to the forum!

    We don't know what you are trying to do.
    You want all of the columns in the rows where NBRJOBS_EFFECTIVE_DATE is the date limit before a given date (November 15, 2011 in this example) for all rows in the result set with this NBRJOBS_PIDM? If so, here is one way:

    with         GOT_R_NUM     as
    (
         select       NBRJOBS.NBRJOBS.*,
                NBRBJOB.NBRBJOB.*     -- You may have to give aliases, so that every column has a unique name
         ,       rank () over ( partition by  NBRJOBS.NBRJOBS_PIDM
                                   order by      NBRJOBS.NBRJOBS_EFFECTIVE_DATE     desc
                          )             as R_NUM
         from          POSNCTL.NBRBJOB NBRBJOB
         inner join      POSNCTL.NBRJOBS NBRJOBS       on    (NBRBJOB.NBRBJOB_PIDM = NBRJOBS.NBRJOBS_PIDM)
                                            and      (NBRBJOB.NBRBJOB_POSN = NBRJOBS.NBRJOBS_POSN)
                                      and      (NBRBJOB.NBRBJOB_SUFF = NBRJOBS.NBRJOBS_SUFF)
         where       NBRJOBS.NBRJOBS_SUFF             != 'LS'       -- Is this what you meant?
         and        NBRBJOB.NBRBJOB_CONTRACT_TYPE   ='P'
         and       NBRJOBS.NBRJOBS_EFFECTIVE_DATE  <= to_date ('2011/11/15', 'yyyy/mm/dd')
    )
    select       *     -- Or list all columns except R_NUM
    from       GOT_R_NUM
    where       R_NUM          = 1
    order by  NBRJOBS_PIDM
    ;
    

    Normally this site does not display the <>inequality operator; He thinks it's some kind of beacon.
    Whenever you post on this site, use the other inequality operator (equivalent), *! = *.

    I hope that answers your question.
    If not, post a small example of data (CREATE TABLE and INSERT, only relevant columns instructions) for all the tables involved and the results desired from these data.
    Explain, using specific examples, how you get these results from these data.
    Always tell what version of Oracle you are using.
    You will get better results faster if you always include this information whenever you have a problem.

  • Join of tables?

    Hello


    My 1st question
    Sometimes i have hard time in deciding the weather to use equi join or left join or right join ?? 
    
    After looking at the data model i can understand how the tables can be joined on what attribute but i lack in making decision weather to use left join or right join for one to many or many to one relationships 
    
    I know the concept of right join and left join but i get confused in what scenario i need to use left join or right join and what join to use for one to many relationships or many to one relationships
    
    If you have any techniques or suggetions how to use them that will be great!!
    My 2nd question




    ___Table1___ TableA
    | | | |
    Table2, table3 table 4 < - TableC - TableB-|

    Table 1 a 1 of many relationships of table2, table 3, table 4

    I, e Table1-> table 2, table 3, table 4

    Table A has many relationships in table 1 B, i, e TableA-> table B

    Table B has 1 in-several in Table C, i, e table B-> table C

    Table C has many relationships in table 4, i, e 1 C table-> table 4


    I know the attributes to use to join these tables, but my question is what join what I use left join or right join or Equi join (I don't think I can use this)


    Something like that in my SQL query in where clause (I don't know if this is right).

    Where
    Table1. ID = table2. ID
    or table1.my_field = table3.id
    or table1.my_field = table4.id
    or tableA. ID = tableB.id---(ce que je dois opérateur OR ou opérateur AND???)
    or tableB.id = TableC.id
    or tablec.id = table4.id

    I don't know if this right or do I have to use the left join on right join or and or operator operator 'OR' is something I m really confued subject.




    Any advice greatly appriciated thank you!

    Published by: user642297 on May 12, 2010 09:49

    Published by: user642297 on May 12, 2010 09:51

    Apart from referring to various documents and examples...
    Use the following examples as 'Playground' and experience to get an idea of the various "joins".

    -- SETUP for examples...
    drop table A;
    drop table B;
    drop table C;
    
    create table a (ca int, sa varchar2(50));
    
    create table b (cb int, sb varchar2(50));
    
    create table c (cc int, sc varchar2(50));
    
    insert into A
    select * from
    (
    select level myid, to_char( to_date( level,'J'),'Jsp') mystr
    from dual connect by level < 11
    );
    commit;
    
    insert into B
    select * from
    (
    select level myid, to_char( to_date( level,'J'),'Jsp') mystr
    from dual connect by level < 21
    )
    where mod(myid,2) = 0;
    commit;
    
    insert into C
    select * from
    (
    select level myid, to_char( to_date( level,'J'),'Jsp') mystr
    from dual connect by level < 11
    )
    where myid < 6;
    commit;
    
    -- Verify the setup
    select * from A;
    
    select * from B;
    
    select * from C;
    
    -- **************************************************************
    -- Requirement EQUI JOIN 1. (AKA INNER JOIN)
    -- To select rows from A and MATCHING rows from B
    -- use A JOIN B or B JOIN A
    --
    -- ANSI SQL syntax
    select * from
    A JOIN B
    on (A.CA = B.CB)
    ;
    -- **** OR ****
    select * from
    B JOIN A
    on (A.CA = B.CB)
    ;
    -- OR Traditional Oracle syntax
    select * from A, B
    where A.CA = B.CB
    ;
    
    -- **************************************************************
    -- Requirement EQUI JOIN 2. (AKA INNER JOIN)
    -- To select rows from A and MATCHING rows from B and matching
    -- rows from C
    -- use A JOIN B JOIN C
    --
    -- ANSI SQL syntax
    select * from
    A JOIN B
    on (A.CA = B.CB)
    JOIN C
    on(B.CB = C.CC)
    ;
    -- OR Traditional Oracle syntax
    select * from A, B, C
    where A.CA = B.CB
      and B.CB = C.CC
    ;
    
    -- **************************************************************
    -- Requirement OUTER JOIN 1.
    -- To select ALL rows from A and ONLY MATCHING rows from B
    -- use A LEFT OUTER JOIN B or B RIGHT OUTER JOIN A
    --
    -- The columns for table B will have NULL value where a
    -- match for A is not found
    --
    -- ANSI SQL syntax
    select * from
    A LEFT OUTER JOIN B
    on (A.CA = B.CB)
    ;
    -- **** OR ****
    select * from
    B RIGHT OUTER JOIN A
    on (A.CA = B.CB)
    ;
    -- OR Traditional Oracle syntax
    select * from A, B
    where A.CA = B.CB(+)
    ;
    ----------------------------------------------------------
    -- The queries above are EQUIVALENT - return the same
    -- result set.
    -- **** However note the "order" in which the rows are
    --      returned by default.
    ----------------------------------------------------------
    
    -- **************************************************************
    -- Requirement OUTER JOIN 2.
    -- To select ALL rows from B and ONLY MATCHING rows from A
    -- use B LEFT OUTER JOIN A or A RIGHT OUTER JOIN B
    --
    -- The columns for table A will have NULL value where a
    -- match for B is not found
    --
    -- ANSI SQL syntax
    select * from
    B LEFT OUTER JOIN A
    on (A.CA = B.CB)
    ;
    -- **** OR ****
    select * from
    A RIGHT OUTER JOIN B
    on (A.CA = B.CB)
    ;
    -- Traditional Oracle syntax
    select * from A, B
    where A.CA(+) = B.CB
    ;
    
    -- **************************************************************
    -- Requirement OUTER JOIN 3.
    -- To select ALL rows from A and ONLY MATCHING rows from B
    -- AND select those rows from C that match rows from B
    --
    -- ANSI SQL syntax
    select * from
    A LEFT OUTER JOIN B
    on (A.CA = B.CB)
     LEFT OUTER JOIN C
    on (B.CB = C.CC)
    ;
    -- OR Traditional Oracle syntax
    select * from A, B, C
    where A.CA = B.CB(+)
      and B.CB = C.CC(+)
    ;
    ----------------------------------------------------------
    -- and So on...
    
    -- **************************************************************
    -- Requirement FULL JOIN 3.
    -- To select ALL rows from A and ALL rows from B
    -- AND MATCH the rows from A and B that match, but return even
    -- the unmatching rows.
    --
    -- ANSI SQL syntax
    select * from
    A FULL OUTER JOIN B
    on (A.CA = B.CB)
    ;
    -- OR Traditional Oracle syntax
    -- There is no equivalent for FULL OUTER join in traditional
    -- syntax. (Though it can be achieved using other means)
    -----------------------------------------------------------------
    

    VR,
    Sudhakar B.

  • Case Based Condition of inner join in SQL query

    Hi Experts,
    CREATE TABLE PRODUCT_PRICE(PRODUCT_ID INTEGER,PRICE FLOAT);
    INSERT INTO PRODUCT_PRICE VALUES(1,1);
    INSERT INTO PRODUCT_PRICE VALUES(2,2);
    INSERT INTO PRODUCT_PRICE VALUES(3,1);
    INSERT INTO PRODUCT_PRICE VALUES(4,1);
    INSERT INTO PRODUCT_PRICE VALUES(5,3);
    INSERT INTO PRODUCT_PRICE VALUES(0,4);
    CREATE TABLE PRODUCT_TABLE (PRODUCTID INTEGER,OTHERID INTEGER);
    INSERT INTO PRODUCT_TABLE VALUES (1,0);
    INSERT INTO PRODUCT_TABLE VALUES (2,0);
    INSERT INTO PRODUCT_TABLE VALUES (3,1);
    INSERT INTO PRODUCT_TABLE VALUES (4,1);
    INSERT INTO PRODUCT_TABLE VALUES (5,2);
    I need to match the product_id = 0 to get the price of the product when there is othersid in the product table (otherid > 0). For this I created the query below.
    SELECT 
        PRODUCT_ID,
        PRICE 
    FROM 
        PRODUCT_TABLE
        INNER JOIN PRODUCT_PRICE ON PRODUCT_ID=PRODUCTID
    WHERE
        OTHERID=0
    UNION ALL
    SELECT 
        PRODUCT_ID,
        PRICE 
    FROM 
        PRODUCT_TABLE
        INNER JOIN PRODUCT_PRICE ON PRODUCT_ID=0
    WHERE
        OTHERID>0;
    My Question is, is that any way the SQLQuery above can be simplified in CASES and INTERNAL CONDITION JOIN in a single SQL QUERY?

    I can work around something like that,
    SELECT 
        PRODUCT_ID,
        PRICE 
    FROM 
        PRODUCT_TABLE
        INNER JOIN PRODUCT_PRICE ON * CASE WHEN OTHERID>0 THEN PRODUCT_ID=0 ELSE PRODUCT_ID=PRODUCTID END*
    Thank you
    SELECT CASE WHEN PT.OTHERID = 0 THEN PT.PRODUCTID ELSE 0 END AS PRODUCT_ID, PP.PRICE
      FROM PRODUCT_TABLE PT,  PRODUCT_PRICE PP
        WHERE CASE WHEN PT.OTHERID =0 THEN PT.PRODUCTID ELSE 0 END = PP.PRODUCT_ID
    

    Should it?

  • Multi table query with key foreign null.

    Consider the following tables

    create table student (
     id number not null,
     name varchar2(80),
    primary key(id)
    );
    
    create table course(
      id number not null,
      subject varchar2(120),
      primary key(id)
    );
    
    create table class(
     id number not null,
     name varchar2(80),
     day number,
     course_id number not null,
     primary key(id),
     foreign key(course_id) references course(id)
    );
    
    create table student_course(
      id number not null,
      student_id number not null,
      course_id number not null,
      class_id number,
      primary key(id),
      foreign key(student_id) references student(id),
      foreign key(course_id) references course(id),
      foreign key(class_id) references class(id)
    );
    

    The student may enroll in a course and then a Professor assign to a class, that's why foreign class_id key isn't a constraint not null.

    What I want is to write a query so that the student can see all courses, it is registered for the class, that he has been assigned and the day of the class, but the report should include courses where the student is not assigned to a class again.

    I wrote the following query.

    select
     course.subject,
     class.name,
     class.day
    from
      course,
      class,
      student_course,
      student
    where course.id = student.course_id
    and class.id = student_course.class_id
    and student_course.foititis_id = get_foititis_id
    

    However, I only get the lines where the student_course.class_id is not null.

    I tried various combinations of coalesce, nvl, decode in both the select statement and where statement, but the results where garbage.

    No idea if such a request is possible?

    Thanks in advance for any help.

    Hello

    Thanks for posting the instructions CREATE TABLE.  Don't forget to display instructions INSERT for a litle sample data and the results desired from these sample data.

    odysam wrote:

    ... I wrote the following query.

    1. Select
    2. race. Subject,
    3. Class.Name,
    4. Class.Day
    5. Of
    6. Of course
    7. class,
    8. student_course,
    9. Student
    10. where course.id = student.course_id
    11. and class.id = student_course.class_id
    12. and student_course.foititis_id = get_foititis_id

    However, I only get the lines where the student_course.class_id is not null.

    I tried various combinations of coalesce, nvl, decode in both the select statement and where statement, but the results where garbage.

    No idea if such a request is possible? ...

    It's logical.  The condition on line 11

    Class.ID = student_course.class_id

    will not be TRUE is student.course.class_id is null.

    As Someoneelse said, looks like you need an Outer Join.

    Inner joins, as you use above, produce results only when a row in a table has one matching row in another table.

    In this case (as far as I can tell without data sample or results), you want to display the rows in a table with their matching rows When THERE is a MATCHING ROWS, but you want to show each row of the first table in any case, if corresponding lines.  This is an outer join.

  • Inner join and 'PIVOT' results

    Good day to all;

    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    PL/SQL Release 10.2.0.4.0 - Production
    "CORE 10.2.0.4.0 Production."
    AMT for Solaris: release 10.2.0.4.0 - Production
    NLSRTL Version 10.2.0.4.0 - Production


    I have 2 paintings I want to do a query on and then "pivot" results. I understand that, since it is 10 g using the PIVOT operator is not supported.
    (Corrected code :)) issues
    create table CT
    (
    DESIGN_ID NUMBER,
    CT_ID VARCHAR2(15)  
    )
    INSERT INTO CT VALUES ('654321','10QWER123456');
    INSERT INTO CT VALUES ('987654','7ASDF654987');
    INSERT INTO CT VALUES ('321654','82CHEV852963');
     
    create table CXRF
    (
    DESIGN_ID NUMBER,    
    ROW_SEQ_NBR NUMBER,    
    XREF_CT_ID VARCHAR2(15)  
    )
    INSERT INTO CXRF VALUES ('654321','1','25ABCD');
    INSERT INTO CXRF VALUES ('654321','2','262ABCD');
    INSERT INTO CXRF VALUES ('987654','1','14WXYZ');
    INSERT INTO CXRF VALUES ('987654','2','34FRED');
    INSERT INTO CXRF VALUES ('321654','1','1TOM');
    -Oops, measure twice cut once...
    select design_id,
            ct_id,
            xref_ct_id
      from cxrf
         INNER JOIN
           ct
       on(ct.design_id = cxrf.design_id) 
    Expected results would look like this:
    DESIGN_ID             CT_ID            XREF_CT_1     XREF_CT_2
       654321       10QWER123456        25ABCD         262ABCD
    Published by: GMoney on 9 may 2013 08:47

    Published by: GMoney on 9 may 2013 08:49

    Thanks for posting examples of data and version, however, as said, it would be better if you can test, DDLS is full of typos.

    Did you visit the FAQ before posting?

    {message: id = 9360005}

    There are also effective methods in previous versions of 11 g data pivot.
    For example:

    SQL> select ct.design_id
      2       , ct.ct_id
      3       , min(case when cxrf.row_seq_nbr = 1 then cxrf.xref_ct_id end) as XREF_CT_1
      4       , min(case when cxrf.row_seq_nbr = 2 then cxrf.xref_ct_id end) as XREF_CT_2
      5  from cxrf
      6       join ct on (ct.design_id = cxrf.design_id)
      7  group by ct.design_id, ct.ct_id ;
    
     DESIGN_ID CT_ID        XREF_CT_1    XREF_CT_2
    ---------- ------------ ------------ ------------
        654321 10QWER123456 25ABCD       262ABCD
        987654 7ASDF654987  14WXYZ       34FRED
        321654 82CHEV852963 1TOM
     
    
  • Join the tables in the responses

    I would like to know if it is possible to join the tables together as below in the answers?

    Select a.Field1, b.Field1
    FROM tableA an outer join left tableA b on
    a.Field1 = b.Field

    If you want to make an INNER JOIN, and then type INNER JOIN instead of LEFT INNER JOIN.

    If you want to left outer join and LEFT OUTER JOIN instead of INTERNAL LEFT JOIN type.

    Nothing asked as a left inner join. That is why it gives error + [nQSError: 27002] near +.

    Thank you

  • How do the query select outer join to a report of the APEX

    Hi all

    I'm Ann.

    I have a select statement that is used to calculate statistics for a month (October 2012 in this example)
    Select ph.phase_number
    sum ((case
    WHEN ph.date_finished IS NULL or ph.date_finished > last_day (TO_DATE (' ' Oct 2012 ', ' MY YYYY' "))
    THEN last_day (TO_DATE (' ' Oct 2012 ', ' MY YYYY' "))
    Of OTHER ph.date_finished
    END)
    (-ph.date_started + 1) / count (def.def_id) as avg_days
    Ph phase_membership
    inner join court_engagement this on ph.mpm_eng_id = ce.engagement_id
    join in-house defendant def on ce.defendant_id = def.def_id
    where def.active = 1
    and ph.date_started < = last_day (TO_DATE (' ' Oct 2012 ', ' MY YYYY' "))
    and ph.active = 1
    and UPPER (ce.court_name) LIKE '% '.
    Rollup Group (phase_number)
    ;

    The result is as below
    Phase_Number AVG_DAYS
    Phase One 8.6666666666666667
    Phase two 14.6
    Phase three 12
    11.4615365

    I have another list of selection mainly the list of months between two date value.
    Select to_char (which_month, 'LUN YYYY') as display_month
    de)
    Select add_months (to_date (' ' August 2012 ', ' MY YYYY' "), rownum-1) which_month
    of object
    where
    rownum < = months_between (to_date (' ' Oct 2012 ', ' MY YYYY' "), add_months (to_date (' ' August 2012", "MY YYYY"), - 1))
    order of which_month)

    The query result is as below

    DISPLAY_MONTH

    AUGUST 2012
    SEP 2012
    OCT 2012

    Is it possible I can join these two select statement above to generate a comparable result:

    Days of month Phase number Avg
    August 2012 Phase One 8.666
    Sep 2012 Phase One 7.66
    Oct 2012 Phase One 5,66
    August 2012 Phase two 8.666
    Sep 2012 Phase two 7.66
    Oct 2012 Phase two 5,66
    August 2012 Phase three 8.666
    Sep 2012 Phase three 7.66
    Oct 2012 Phase three 5,66

    Or
    Days of month Phase number Avg
    August 2012 Phase One 8.666
    August 2012 Phase two 7.66
    August 2012 Phase three 5,66
    Sep 2012 Phase One 8.666
    Sep 2012 Phase two 7.66
    Sep 2012 Phase three 5,66
    Oct 2012 Phase One 8.666
    Oct 2012 Phase two 7.66
    Oct 2012 Phase three 5,66

    And it can be controlled by Phase number or month.
    My other colleague suggested I should use a left outer join, but after having tried many ways, I'm still stuck.

    I tried select is
    Select a.display_month, b.* in)
    Select to_char (which_month, 'LUN YYYY') as display_month
    de)
    Select add_months (to_date (' ' August 2012 ', ' MY YYYY' "), rownum-1) which_month
    of object
    where
    rownum < = months_between (to_date (' ' Oct 2012 ', ' MY YYYY' "), add_months (to_date (' ' August 2012", "MY YYYY"), - 1))
    order which_month)) a left outer join

    (Select to_char (ph.date_finished, 'MY YYYY') as join_month, ph.phase_number)
    sum ((case
    WHEN ph.date_finished IS NULL or ph.date_finished > last_day (TO_DATE (a.display_month, 'MY YYYY'))
    THEN last_day (TO_DATE (a.display_month, 'MY YYYY'))
    Of OTHER ph.date_finished
    END)
    (-ph.date_started + 1) / count (def.def_id) as avg_days
    Ph phase_membership
    inner join court_engagement this on ph.mpm_eng_id = ce.engagement_id
    join in-house defendant def on ce.defendant_id = def.def_id
    where def.active = 1
    and ph.date_started < = last_day (TO_DATE (a.display_month, 'MY YYYY'))
    and ph.active = 1
    and UPPER (ce.court_name) LIKE '% '.
    To_char (ph.date_finished, 'MY YYYY'), group (phase_number) rollup) b
    On a.display_month = b.join_month

    but then I get an error
    SQL error: ORA-00904: "A." "" DISPLAY_MONTH ": invalid identifier

    I need to view a report on the APEX with option for people to download at least format CSV.
    Already 1 inteactive report in the page, so I don't think adds another interactive report without using the iframe trick.

    If any of you have any ideas, please help.

    Thank you very much.

    Ann

    Hello Ann,.

    Frank has done a very good job. I am also impressed.

    Is in regard to your correction to his question, the problem is on this replacement you did

    last_day(TO_DATE(am.which_month,'MON YYYY'))
    

    AM.which_month is already a date type, and you don't need to convert it to this day.
    Here is the correct way:

    last_day(am.which_month)
    

    There are also sometimes with the data you've posted have no line for this month. So I also added a function NVL to display 0 under avg_days for these cases.

    Here is my corrected query:

    DEFINE startmonth = "Aug 2012";
    DEFINE endmonth   = "Oct 2012";
    WITH  all_months  AS
    (
       SELECT ADD_MONTHS(to_date('&startmonth','MON YYYY'), ROWNUM-1) AS which_month
       ,      ADD_MONTHS(to_date('&startmonth','MON YYYY'), ROWNUM  ) AS next_month
       from all_objects
       where
       rownum <= months_between(to_date('&endmonth','MON YYYY'), add_months(to_date('&startmonth','MON YYYY'), -1))
    )
    SELECT TO_CHAR (am.which_month, 'Mon YYYY')  AS month
         , ph.phase_number
         , NVL(sum ( (CASE
                     WHEN ph.date_finished IS NULL OR ph.date_finished > last_day(am.which_month)
                     THEN last_day(am.which_month)
                     ELSE ph.date_finished
                  END
                 ) - ph.date_started + 1
               ) / count(def.def_id), 0) as avg_days
      FROM all_months am
           LEFT OUTER JOIN  a_phase_membership  ph  PARTITION BY (ph.phase_number)
              ON  am.which_month <= ph.date_started
              AND am.next_month  >  ph.date_started
              AND ph.date_started <= last_day(am.which_month)  -- May not be needed
              AND ph.active = 1
           LEFT OUTER JOIN  a_engagement  ce
              ON  ph.mpm_eng_id = ce.engagement_id
              AND ce.court_name IS NOT NULL  -- or something involving LIKE
           LEFT OUTER join  a_defendant     def
              ON  ce.defendant_id = def.def_id
              AND def.active = 1
     GROUP BY ROLLUP(phase_number, am.which_month)
     ORDER BY  am.which_month
            ,  ph.phase_number
    ;
    
    The output is:
    MONTH    PHASE_NUMBER           AVG_DAYS
    -------- -------------------- ----------
    Aug 2012 PHASE ONE                     0
    Aug 2012 PHASE THREE                   0
    Aug 2012 PHASE TWO                     0
    Sep 2012 PHASE ONE                    12
    Sep 2012 PHASE THREE                   1
    Sep 2012 PHASE TWO                     9
    Oct 2012 PHASE ONE                     8
    Oct 2012 PHASE THREE                   0
    Oct 2012 PHASE TWO                    14
             PHASE ONE                    11
             PHASE THREE                   1
             PHASE TWO                  11.5
                                  9.71428571
    

    I don't know if that's really what you want. In the case check it and let me know.

    Kind regards.
    Al

  • inner join is not eliminating duplicates!

    Name of the table is customers

    VALUE CITY SIDE NUMS CNAME
    1 2001 Hoffman 100 1001 London
    2 Rome 2002 200 1003 Giovanni
    3 2003 Liu San Jose 200 1002
    4 2004 grass Berlin 300 1002
    5 2006 Clemens 100 1001 London
    6 2008 Cisneros San Jose 300 1007
    7 2007 perish Rome 100 1004

    Query is
    To find all pairs of customers having the same side

    I tried:

    SELECT c.cname, cb.cname FROM customers c INNER JOIN customers cb WE cb.rating AND c.cname = c.rating! = cb.cname

    CNAME CNAME
    1 perish Hoffman
    2 Clemens Hoffman
    3 Liu Giovanni
    4 Giovanni Liu
    5 Cisneros grass
    6 perira Clemens
    7 Hoffman Clemens
    8 grass Cisneros
    Clemens 9 perish
    10 Hoffman perish


    Ideally, it should up to 5 rows, but it does not return these lines for an e.g. Hoffman perish since I'm Perira Hoffman already. Your answers will be appreciated.

    Thank you
    Vaibhav

    Hi, Vaibhav,

    914683 wrote:
    Name of the table is customers

    VALUE CITY SIDE NUMS CNAME
    1 2001 Hoffman 100 1001 London
    2 Rome 2002 200 1003 Giovanni
    3 2003 Liu San Jose 200 1002
    4 2004 grass Berlin 300 1002
    5 2006 Clemens 100 1001 London
    6 2008 Cisneros San Jose 300 1007
    7 2007 perish Rome 100 1004

    Query is
    To find all pairs of customers having the same side

    I tried:

    SELECT c.cname, cb.cname FROM customers c INNER JOIN customers cb WE cb.rating AND c.cname = c.rating! = cb.cname

    Perhaps what you want is

    SELECT      c.cname
    ,         cb.cname
    FROM          customers  c
    INNER JOIN  customers  cb  ON   c.rating  = cb.rating
                                       AND  c.cname       < cb.cname     -- not !=
    ;
    

    CNAME CNAME
    1 perish Hoffman
    2 Clemens Hoffman
    3 Liu Giovanni
    4 Giovanni Liu
    5 Cisneros grass
    6 perira Clemens
    7 Hoffman Clemens
    8 grass Cisneros
    Clemens 9 perish
    10 Hoffman perish

    The title you chose for this thread is "inner join is not eliminating duplicates!
    Inner joins (or other types of joints) are not supposed to remove duplicates. Use SELECT DISTINCT to remove duplicates, which is exactly the same lines.
    You don't have to duplicate. For example, these lines of your result set:

    `        CNAME     CNAME
    1     Perira     Hoffman
    10     Hoffman     Perira
    

    are not identical; Indeed, the two columns are different.

    Ideally, it should up to 5 rows, but it does not return these lines for an e.g. Hoffman perish since I'm Perira Hoffman already.

    Please report the exact output of the sample data you want. (As said by Hoek, post CREATE TABLE and INSERT statements for the sample data too.)

  • Issue of inner joins

    Hi all
    I have a few tables with samples as:
    CREATE OR REPLACE TABLE hotel
    ( 
         hotel_id             int  NOT NULL ,
         hotel_name           varchar2(50)  NULL ,
         hotel_address        varchar2(100)  NULL
    );
    
    CREATE OR REPLACE TABLE people_type
    ( 
         people_type_id       int  NOT NULL ,
         type_des             varchar2(30)  NOT NULL
    );
    
    CREATE OR REPLACE TABLE hotel_people
    ( 
         hotel_id                int  NOT NULL ,
         people_type_id      int  NOT NULL ,
         age_min                int  NULL ,
         age_max               int  NULL
    );
    
    CREATE OR REPLACE TABLE hotel_service
    ( 
         hotel_id              int  NOT NULL ,
         qty_room             int  NOT NULL ,
         qty_people           int  NOT NULL,
         qty_people_extra      int  NOT NULL
    );
    
    insert into hotel(hotel_id, hotel_name, hotel_address)
    values(1,'hotel1','hotel1 address1');
    insert into hotel(hotel_id, hotel_name, hotel_address)
    values(2,'hotel2','hotel2 address2');
    insert into hotel(hotel_id, hotel_name, hotel_address)
    values(3,'hotel3','hotel3 address3');
    insert into hotel(hotel_id, hotel_name, hotel_address)
    values(4,'hotel4','hotel4 address4');
    
    insert into people_type (people_type_id, type_des)
    values (1,'Baby');
    insert into people_type (people_type_id, type_des)
    values (2,'Young');
    insert into people_type (people_type_id, type_des)
    values (3,'Adult');
    
    insert into hotel_people (hotel_id, people_type_id, age_min, age_max)
    values (1,1,0,2);
    insert into hotel_people (hotel_id, people_type_id, age_min, age_max)
    values (1,2,3,10);
    insert into hotel_people (hotel_id, people_type_id, age_min, age_max)
    values (1,3,11,200);
    
    insert into hotel_people (hotel_id, people_type_id, age_min, age_max)
    values (2,2,3,17);
    insert into hotel_people (hotel_id, people_type_id, age_min, age_max)
    values (2,3,18,200);
    
    insert into hotel_people (hotel_id, people_type_id, age_min, age_max)
    values (3,3,18,200);
    
    insert into hotel_people (hotel_id, people_type_id, age_min, age_max)
    values (4,1,0,2);
    insert into hotel_people (hotel_id, people_type_id, age_min, age_max)
    values (4,2,3,10);
    insert into hotel_people (hotel_id, people_type_id, age_min, age_max)
    values (4,3,11,200);
    
    insert into hotel_service (hotel_id, qty_room, qty_people,qty_people_extra)
    values (1,10,2,1);
    insert into hotel_service (hotel_id, qty_room, qty_people,qty_people_extra)
    values (1,5,4,0);
    insert into hotel_service (hotel_id, qty_room, qty_people,qty_people_extra)
    values (2,6,2,1);
    insert into hotel_service (hotel_id, qty_room, qty_people,qty_people_extra)
    values (2,12,3,1);
    insert into hotel_service (hotel_id, qty_room, qty_people,qty_people_extra)
    values (3,10,2,1);
    insert into hotel_service (hotel_id, qty_room, qty_people,qty_people_extra)
    values (3,5,4,0);
    insert into hotel_service (hotel_id, qty_room, qty_people,qty_people_extra)
    values (4,6,2,1);
    insert into hotel_service (hotel_id, qty_room, qty_people,qty_people_extra)
    values (4,12,3,1);
    As you can see I have Hotels with basic information, persons of type hotel_people (1:baby, 2:young and 3:Adult), which contains the type of people that each hotel can accommodate with min max age and hotel_service that contains the info from the number of rooms and the amount of people that can be in each room.
    I'm trying to get the records that match my condition as:
    1. I want to get the hotels that can accommodate 4 pieces with adults of 3 for each room.
    2 get hotels that can accommodate 6 rooms 2 where 2 of the bedrooms can have 1 young (3 people per room) and young people 9 years.

    For 1:
    select h.hotel_id, h.hotel_name, ss.qty_room, t.type_des, ss.qty_people, p.age_min, p.age_max
    from hotel h
    inner join hotel_service ss on h.hotel_id = ss.hotel_id
    inner join hotel_people p on h.hotel_id = p.hotel_id
    inner join people_type t on p.people_type_id = t.people_type_id
    where ss.qty_room >= 4
    and t.people_type_id = 3
    and ss.qty_people >= 3
    For 2:
    select h.hotel_id, h.hotel_name, ss.qty_room, t.type_des, ss.qty_people, p.age_min, p.age_max
    from hotel h
    inner join hotel_service ss on h.hotel_id = ss.hotel_id
    inner join hotel_people p on h.hotel_id = p.hotel_id
    inner join people_type t on p.people_type_id = t.people_type_id
    where ss.qty_room >= 6
    and ss.qty_people >= 3
    and t.people_type_id in (2,3)
    and 9 between p.age_min and p.age_max
    This does not work, the start of the query becomes more complex if I try to search for multiple rooms with a different number of people and children of different ages.
    Can anyone help with this?
    Thank you

    Published by: user9542267 on April 3, 2012 22:26

    Hello

    user9542267 wrote:
    ... Yes, what I need is a hotel that can accommodate TWO adults and youth. What do you mean by two copies?

    Right now I read something on the Grand Duke by Gilbert. I also have a book with the complete works of Gilbert, so I can leave it open, and when I see a reference in the commentary, I see exactly what the author is talking about in the book. However, when the comment compares some parts of this game to the other plays of Gilbert, The Yeomen of the Guard , it gets hard, because I have to keep changing the pages in the complete works, and I can't see both at the same time. It would be much easier if I could get a full second copy of the work; then I could leave a copy of the Grand Duke and leave the other copy open to The Yeomen of the Guard . This is similar to what you should do with the table of hotel_people, and what I do with the table scott.emp below.

    Imagine (using tables in the scott schema) you have to find the departments where both an analyst and a clerk to work.
    This:

    SELECT DISTINCT
              d.*
    FROM       scott.dept     d
    JOIN       scott.emp     e  ON     d.deptno     = e.deptno
    WHERE       job          IN ('ANALYST', 'CLERK')
    ORDER BY  d.deptno
    ;
    

    product

    DEPTNO DNAME          LOC
    ------ -------------- -------------
        10 ACCOUNTING     NEW YORK
        20 RESEARCH       DALLAS
        30 SALES          CHICAGO
    

    because all these departments have either an analyst or a clerk. However, only deptno = 20 a time .
    If, instead of a single table of big job, you have a separate table for each Olympic Games, then you might do something like this:

    SELECT DISTINCT
              d.*
    FROM       scott.dept     d
    JOIN       analyst     a  ON     d.deptno     = a.deptno
    JOIN       clerk          c  ON     d.deptno     = c.deptno
    ORDER BY  d.deptno
    ;
    

    Of course, you don't have tables separated like that, but you could generate result sets who behaved as separte tables, for example:

    WITH     analyst          AS
    (
         SELECT  *
         FROM     scott.emp
         WHERE     job     = 'ANALYST'
    )
    ,     clerk          AS
    (
         SELECT  *
         FROM     scott.emp
         WHERE     job     = 'CLERK'
    )
    SELECT DISTINCT
              d.*
    FROM       scott.dept     d
    JOIN       analyst     a  ON     d.deptno     = a.deptno
    JOIN       clerk          c  ON     d.deptno     = c.deptno
    ORDER BY  d.deptno
    ;
    

    Note that the main request is exactly what I posted earlier.
    What produces the right output:

    DEPTNO DNAME          LOC
    ------ -------------- -------------
        20 RESEARCH       DALLAS
    

    There is no need to actually generate separate result sets, however. You can use two copies of the table scott.emp in the same query, as follows:

    SELECT DISTINCT
              d.*
    FROM       scott.dept     d
    JOIN       scott.emp     a  ON     d.deptno     = a.deptno
    JOIN       scott.emp     c  ON     d.deptno     = c.deptno
    WHERE       a.job          = 'ANALYST'
    AND       c.job          = 'CLERK'
    ORDER BY  d.deptno
    ;
    

Maybe you are looking for

  • Why a new MacBook have a load cycle count of 18

    I just bought a brand new MacBook(early 2016) last week and immediately noticed that the number of cycle load was 18 years old. Is this normal or have I been given a return or a refurb? Thank you!

  • How to set the Anti Aliasing in Blackberry Storm?

    I m drawing in a bitmap as... bitmap[i] = new Bitmap(60, 60); Graphics g = new Graphics(bitmap[i]); g.setColor(Color.BLACK); g.drawLine(....); Now how to put Anti-Aliasing on before g.drawLine ()?

  • Help! Creative cloud desktop application

    HelloIm trying to use the desktop application to install some applications from adobe. His jelly and whem it works (after removing the preferences and installation using the suggestion on this thread):https://forums.Adobe.com/thread/2058432?q=creativ

  • Update InDesign and Illustrator, but Photoshop was not updated. Why? What can I do?

    In November, has been updated InDesign and Illustrator, but Photoshop has not been updated. What should do? My son has CC and all this programs has been updated

  • How to install Windows 7 download

    VMWare fusion is installed on my MacBook Pro.Windows 7 license.Windows 7 downloaded three files:Win7-HP-retail-en-us-x86_1.boxWin7-HP-retail-en-us-x86_2.boxWin7-HP-Retail-en-US-x86.exeWhen you create a new virtual environment, none of the clear optio