Double outer join on table

Hi
Let's say I have three tables ORDERS, PRODUCT and CLIENT. I want a query that will give me all PRODUCT and CLIENT combinations and the total sum of orders if it has one. If I try to do this:
select P.NAME, C.NAME, SUM(O.AMOUNT)
from PRODUCT P, CLIENT C, ORDER O
where P.ID = O.PRODUCT_ID(+) and
C.ID = O.CLIENT_ID(+)
I get an error where I cannot double outer join a table.
Any ideas?

3360 wrote:
BluShadow wrote:
and ANSI allows a little more in those terms than regular oracle syntax.It is different, but it cannot do anything that regular equi-joins cannot do. In most cases the optimizer converts ANSI joins to regular joins for execution, and this additional conversion has been subject to numerous bugs.ANSI does allow for doing things that regular Oracle syntax cannot do.
Here's an ANSI way to do it if you only want to see those client/product combinations that exist in orders table:
SQL> with product as (
  2     select 101 id, 'Product 1' name from dual union all
  3     select 102 id, 'Product 2' name from dual union all
  4     select 103 id, 'Product 3' name from dual
  5  ), client as (
  6     select 11 id, 'Client 1' name from dual union all
  7     select 12 id, 'Client 2' name from dual
  8  ), orders as (
  9     select 11 client_id, 101 product_id, 10 amount from dual union all
10     select 11 client_id, 103 product_id, 30 amount from dual union all
11     select 12 client_id, 102 product_id, 20 amount from dual union all
12     select 12 client_id, 102 product_id, 20 amount from dual
13  )
14  --
15  -- end-of-test-data
16  --
17  select p.name
18       , c.name
19       , sum(o.amount)
20    from orders o
21    left outer join product p
22         on p.id = o.product_id
23    left outer join client c
24         on c.id = o.client_id
25   group by
26         p.name
27       , c.name
28   order by
29         p.name
30       , c.name
31  /
NAME      NAME     SUM(O.AMOUNT)
Product 1 Client 1            10
Product 2 Client 2            40
Product 3 Client 1            30(If the datamodel is good with product_id being a foreign key of product.id and the same with client, then outer join is not really necessary, I know. But for the sake of argument assume bad datamodel that needs outer join ;-) )
The above ANSI can be written in regular Oracle syntax as well:
SQL> with product as (
  2     select 101 id, 'Product 1' name from dual union all
  3     select 102 id, 'Product 2' name from dual union all
  4     select 103 id, 'Product 3' name from dual
  5  ), client as (
  6     select 11 id, 'Client 1' name from dual union all
  7     select 12 id, 'Client 2' name from dual
  8  ), orders as (
  9     select 11 client_id, 101 product_id, 10 amount from dual union all
10     select 11 client_id, 103 product_id, 30 amount from dual union all
11     select 12 client_id, 102 product_id, 20 amount from dual union all
12     select 12 client_id, 102 product_id, 20 amount from dual
13  )
14  --
15  -- end-of-test-data
16  --
17  select p.name
18       , c.name
19       , sum(o.amount)
20    from orders o, product p, client c
21   where p.id(+) = o.product_id
22     and c.id(+) = o.client_id
23   group by
24         p.name
25       , c.name
26   order by
27         p.name
28       , c.name
29  /
NAME      NAME     SUM(O.AMOUNT)
Product 1 Client 1            10
Product 2 Client 2            40
Product 3 Client 1            30Many old Oracle coders will probably state that this syntax is much easier. For a simple case like this I find both ways easy. But I have complex cases where I much prefer ANSI where I can easily distinguish join predicates from filter predicates. It is a matter of opinion, I know ;-)
But if we then take the original post as a literal specification, that we want all combinations of products and clients and then the sum of order amount if it exists, null otherwise.
This can be written easily in ANSI notation:
SQL> with product as (
  2     select 101 id, 'Product 1' name from dual union all
  3     select 102 id, 'Product 2' name from dual union all
  4     select 103 id, 'Product 3' name from dual
  5  ), client as (
  6     select 11 id, 'Client 1' name from dual union all
  7     select 12 id, 'Client 2' name from dual
  8  ), orders as (
  9     select 11 client_id, 101 product_id, 10 amount from dual union all
10     select 11 client_id, 103 product_id, 30 amount from dual union all
11     select 12 client_id, 102 product_id, 20 amount from dual union all
12     select 12 client_id, 102 product_id, 20 amount from dual
13  )
14  --
15  -- end-of-test-data
16  --
17  select p.name
18       , c.name
19       , sum(o.amount)
20    from product p
21   cross join client c
22    left outer join orders o
23         on o.product_id = p.id
24        and o.client_id = c.id
25   group by
26         p.name
27       , c.name
28   order by
29         p.name
30       , c.name
31  /
NAME      NAME     SUM(O.AMOUNT)
Product 1 Client 1            10
Product 1 Client 2
Product 2 Client 1
Product 2 Client 2            40
Product 3 Client 1            30
Product 3 Client 2
6 rows selected.ANSI notation allows outer join with more than one table.
Regular Oracle syntax could only do this by creating an inline view of the cartesian join and then outer joining orders with the inline view. Doable, but not as nice (IMHO) as the ANSI method for a case like this ;-)

Similar Messages

  • Left outer join 3 tables with where-statement

    Hi folks,
    I hope you can understand (and maybe solve) my problem.
    Generally I try to left outer join three tables. The third table is used for a WHERE-statement.
    The three table structures are the following:
    table 1 (user)   
    user1 | key
    table 2 (detail)  
    key | ID
    table 3 (header)
    ID | user2                 
    ...and I want to achieve the following structure (as example filled with data):
    user | key | ID
    |-----|----
    xy    | a    | 001
    xy    | b    | #
    z     | b     | #
    The clue ist the usage of the third table. I need the table to set user1 and user2 equal (WHERE) but there are two problems:
    1) Obviously I can't left outer join two tables with each other. In this case I already used the 'key' of table 1 to join it with the 'key' of table 2. So I can't left outer join the 'ID' of table 2 with the 'ID' of table 3. Error message that I can only left outer join a table once. Any proposals?
    2) I have to include a WHERE to equal user1 with user2. But I am not allowed to use the user2 from table 3 because of the left outer join.
    I tried this coding:
    SELECT auser1 akey b~id INTO TABLE itab FROM ( table1 AS a
      LEFT OUTER JOIN table2 AS b ON akey = bkey )
      LEFT OUTER JOIN table3 AS c ON bID = cID )
      WHERE auser1 = cuser2.
    I would really appreciate your help.
    Regards
    MrclSpdl

    IF you want to join a DB table with an internal table, you need to use the 'FOR ALL ENTRIES' statement.
    select dbfields
    into table itab2
    from dbtab
    for all entries in itab
    where dbfield1 = itab-field1.
    This will get you a second internal table with all the corresponding data for the first selection.  You can then join them with a loop through the first table and a read table on the second table (for 1 - 1 relation) or a nested loop statement on both tables (for 1 - N relation).  Make itab a hashed table when using read table with key, use a sorted table if you need to loop without key access.
    Regards,
    Freek

  • Best way to outer join a table that is doing a sub query

    RDBMS : 11.1.0.7.0
    Hello,
    What is the best way to outer join a table that is doing a sub query? This is a common scenario in EBS for the date tracked tables.
    SELECT papf.full_name, fu.description
      FROM fnd_user fu
          ,per_all_people_f papf
    WHERE fu.user_id = 1772
       AND fu.employee_id = papf.person_id(+)
       AND papf.effective_start_date = (SELECT MAX( per1.effective_start_date )
                                          FROM per_all_people_f per1
                                         WHERE per1.person_id = papf.person_id)Output:
    No output produced because the outer join cannot be done on the sub queryIn this case I did a query in the FROM clause. Is this my best option?
    SELECT papf.full_name, fu.description
      FROM fnd_user fu
          ,(SELECT full_name, person_id
              FROM per_all_people_f papf
             WHERE papf.effective_start_date = (SELECT MAX( per1.effective_start_date )
                                                  FROM per_all_people_f per1
                                                 WHERE per1.person_id = papf.person_id)) papf
    WHERE fu.user_id = 1772
       AND fu.employee_id = papf.person_id(+)Output:
    FULL_NAME     DESCRIPTION
    {null}            John DoeThanks,
    --Johnnie                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Hi,
    BrendanP wrote:
    ... See the adjacent thread for the other with Row_Number().Do you mean {message:id=10564772} ? Which threads are adjacent is always changing. Post a link.
    I think RANK suits the requirements better than ROW_NUMBER:
    WITH    all_matches     AS
         SELECT  papf.full_name
         ,      fu.description
         ,     RANK () OVER ( PARTITION BY  papf.person_id
                               ORDER BY          papf.effective_start_date     DESC
                        )           AS r_num
         FROM             fnd_user             fu
         LEFT OUTER JOIN      per_all_people_f  papf  ON  fu.employee_id  = papf.person_id
         WHERE   fu.user_id  = 1772
    SELECT     full_name
    ,     description
    FROM     all_matches
    WHERE     r_num     = 1
    Johnnie: I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
    See the forum FAQ {message:id=9360002}

  • Join columns of outer join with table have no uniqueness cons

    Hi! I'm getting noizy error in alert log from time to time:
    Join columns of outer join with table <table_name> have no uniqueness constraints
    I've collected all the queries (v$sql, all_source) with montioned table, but non of them produces that error if executed.
    Any hints how to reproduce this error or where else to search that buggy sql join?
    Edited by: user545083 on 25.10.2010 6:21

    Hi
    I think this error is output via an materialized view refresh - check for mviews against the given table which fulfil the issue given in the error text.
    Thanks
    Paul

  • LEFT OUTER JOIN multiple tables - using the 9i syntax

    I've always written my queries using the (+) operator for outer joins. I want to start using the new ANSI standard available in 9i. I can do it when I'm joining two tables in a simple query, but how does it work when I am joining multiple tables?
    Here is an example of some SQL that works with the (+) outer join syntax. How can I convert this to use the LEFT OUTER JOIN syntax?
    SELECT *
    FROM audit_entry aue,
    audit_table aut,
    audit_statement aus,
    audit_row aur,
    audit_row_pkey aup1,
    audit_row_pkey aup2
    WHERE aue.audit_entry_id = aus.audit_entry_id
    AND aut.table_name = 'TEST_AUDITING'
    AND aut.table_owner = 'CLA_JOURNAL'
    AND aus.audit_table_id = aut.audit_table_id
    AND aur.audit_statement_id (+) = aus.audit_statement_id
    AND aup1.audit_row_id (+) = aur.audit_row_id
    AND aup1.pk_column_name (+) = 'TEST_AUDTING_PK_1'
    AND aup2.audit_row_id (+) = aur.audit_row_id
    AND aup2.pk_column_name (+) = 'TEST_AUDITING_PK_2'
    I can join audit_statement to audit_entry easy enough, but then I want to join audit_table to audit_statement, how do I do that, do I start nesting the join statements?
    Thanks
    Richard

    Thanks for getting back so quickly, I have tried the suggested SQL with mixed results:
    SELECT COUNT(*)
    FROM audit_entry aue
    JOIN audit_statement aus ON aue.audit_entry_id = aus.audit_entry_id
    JOIN audit_table aut ON aus.audit_table_id = aut.audit_table_id
    RIGHT OUTER JOIN audit_row aur ON aur.audit_statement_id = aus.audit_statement_id
    RIGHT OUTER JOIN audit_row_pkey aup1 ON aup1.audit_row_id = aur.audit_row_id
    RIGHT OUTER JOIN audit_row_pkey aup2 ON aup2.audit_row_id = aur.audit_row_id
    WHERE aut.table_name = 'TEST_AUDITING_TWO'
    AND aut.table_owner = 'CLA_JOURNAL'
    AND aup1.pk_column_name = 'TEST_AUDTING_PK_1'
    AND aup2.pk_column_name = 'TEST_AUDITING_PK_2'
    I had to change the order slightly, between the first two JOINs but otherwise it executed OK. My problem is, it should only return 175 rows but its returning 30625 rows. If I comment out the second reference to audit_row_pkey I get the expected result:
    SELECT COUNT(*)
    FROM audit_entry aue
    JOIN audit_statement aus ON aue.audit_entry_id = aus.audit_entry_id
    JOIN audit_table aut ON aus.audit_table_id = aut.audit_table_id
    RIGHT OUTER JOIN audit_row aur ON aur.audit_statement_id = aus.audit_statement_id
    RIGHT OUTER JOIN audit_row_pkey aup1 ON aup1.audit_row_id = aur.audit_row_id
    --RIGHT OUTER JOIN audit_row_pkey aup2 ON aup2.audit_row_id = aur.audit_row_id
    WHERE aut.table_name = 'TEST_AUDITING_TWO'
    AND aut.table_owner = 'CLA_JOURNAL'
    AND aup1.pk_column_name = 'TEST_AUDTING_PK_1'
    --AND aup2.pk_column_name = 'TEST_AUDITING_PK_2'
    It looks the same condition is being used in each case but why do I suddenly get so many rows - its joining differently somehow. It must be to do with the order, do I need to bracket the query?
    Thanks again
    Richard

  • Left Outer Joining multiple tables to one source table FAILS with VLD-1511

    Hi all,
    Is it me, or is OWB unable to handle left outer joining 1 source table to multiple other tables?
    I want to load a fact table so I have 1 source table with measures. This table must be outer joined to some dimensions that have their FK in the fact table.
    The SQL statement would look like this (and is perfectly valid):
    select ...
    from input, dim1, dim2
    where input.c1 = dim1.c1(+)
    and input.c2 = dim2.c2(+);
    I put the where clause in the joiner operator and validate, but that gives me message VLD-1511: A table may be outer joined to at most one other table.
    Even splitting this up into one outer join per joiner still gives this message.
    A search and look around on the forum and on metalink shows there are related issues (like bug 3334035). Seemingly creating a view is the work-around to use.....? (ie downgrading owb to a simple gui tool) }-;
    Have other people experienced this problem of not being able to outer join one input table to multiple other tables?
    Thanks,
    Ed

    I have had some feedback from Oracle. It turns out this has to do with 2 issues. Below I have pasted the text that Support gave me:
    <---------- START QUOTE ---------->
    RESEARCH
    =========
    Bug 3437036 KEY LOOKUP DOES NOT DETECT ORA-1417 IN VALIDATE/GENERATE STEP
    Unpublished Bug 4211684 FORWARD PORT OF BUG 3437036
    shows:
    Some more development has been completed when this bug is fixed in Paris.
    The following are the details:
    1. If the join condition contains a full outer join such as
    tab1.c (+) = tab2.c (+) and tab2.c (+) = tab3.c
    then the new validations implemented for this bug do not apply since
    in OWB, full outer join triggers generation of joins in ANSI syntax.
    ANSI syntax does not have the original problem the base bug of this
    bug reported.
    2. If the join condition does not contain any full outer join condition,
    then the join is generated in Oracle join syntax, which is subject two
    several restrictions. The fix to this bug check two of the restrictions.
    3. The first restriction in Oracle syntax is that the outer join operator
    "(+)" can only directly be attached to a column name. If you attach it
    to an expression, such as the following:
    (tab1.c + 1) (+) = tab2.c
    Then there will be an ORA-936 error at the time of mapping deployment.
    For this case, I have added a validation message VLD-1512 to error out
    this situation.
    4. The second restriction in Oracle syntax is that a table can only be
    outer joined to exactly one other table.
    For example, this is an invalid join in Oracle syntax:
    tab1.c (+) = tab2.c and tab1.d (+) = tab3.d
    because tab1 is left outer joined to tab2 and tab3.
    But note that the following is still valid in Oracle syntax:
    tab1.c (+) = tab2.c and tab1.d = tab3.d (+)
    because tab1 is left outer joined to tab2 and right outer joined to tab3.
    So this latter case does not violate the restriction that "same oj" to
    more than 1 table is not allowed.
    If same oj to more than 1 table is specified in a join condition,
    VLD-1511 will be issued, and the map is made invalid.
    <---------- END QUOTE ---------->
    OWB does a partial validation, ie not all access paths are (can be) checked. A full check is only done by the database itself. So some scenarios (like checking whether multiple tables are outer joined the correct way) are not checked, and in this case are flagged with an error (even though it is actually a correct scenario).
    Seemingly this was not flagged with an error in earlier versions of OWB, so beware, OWB behaviour may change when upgrading...
    Alternative solutions are (1) using key lookups, (2) using a view with all outer joins in there, (3) using intermediate result tables between the joins.
    Hope this info helps some people prevent spending too much time on a false error message,
    Ed

  • Outer join two tables with two keys

    Hi,
    I have a question regard outer join,
    I have table A (Aid, ADesc), Table B(Bid, Bdesc), and Table C (Aid, Bid, Cdesc)
    There is data in Table A and B, but Table C is empty
    I want to outer join C with A and B with below query
    select ADesc,Bdesc, Cdest
    from A, B, C
    where A.Aid=C.Aid(+) and B.Bid(+)=C.Bid
    and A.Aid='XXX' and B.Bid(+)='ZZZ'
    The query result show only data in column Adesc , but column BDesc is empty even though there are some data in table B.
    How should the query been modified to correctly show ADESC and Bdesc.
    Thanks
    Vincent

    Guess the below should work:
    Case when records are available in Table C:
    with a as
    (select 'XXX' aid, 'adesc' adesc from dual),
    b as
    (select 'ZZZ' bid, 'bdesc' bdesc from dual),
    c as
    (select 'XXX' aid, 'ZZZ' bid, 'cdest' cdest from dual where 1 = 1)
    select ADesc,Bdesc, C1.Cdest
    from
    A LEFT OUTER JOIN C c1 ON (A.AID = C1.AID AND A.AID = 'XXX'),
    B LEFT OUTER JOIN C C2 ON (B.BID = C2.BID AND B.BID = 'ZZZ');
    Output:
    "ADESC"     "BDESC"     "CDEST"
    "adesc"     "bdesc"     "cdest"Case when table C is empty:
    with a as
    (select 'XXX' aid, 'adesc' adesc from dual),
    b as
    (select 'ZZZ' bid, 'bdesc' bdesc from dual),
    c as
    (select 'XXX' aid, 'ZZZ' bid, 'cdest' cdest from dual where 1 = 2)
    select ADesc,Bdesc, C1.Cdest
    from
    A LEFT OUTER JOIN C c1 ON (A.AID = C1.AID AND A.AID = 'XXX'),
    B LEFT OUTER JOIN C C2 ON (B.BID = C2.BID AND B.BID = 'ZZZ');
    "ADESC"     "BDESC"     "CDEST"
    "adesc"     "bdesc"     ""

  • Outer join two tables with query search record attached to both tables

    When I create a query with two tables that have query search records attached with outer join, PS seems to do a natural join (cartesian). We are on PT8.48.
    Is there a workaround for this issue. I do not want to remove query search record on either of the tables.
    I am trying to create an Emergency contact report. I am using two tables PS_EMPLOYEES and PS_EMERGENCY_CNTCT. Here is the sql PeopleSoft query generated when I did Left outer Join.
    Query SQL:
    SELECT A.EMPLID, A.NAME, A.ADDRESS1, A.CITY, B.PRIMARY_CONTACT, B.ADDRESS1, B.CITY, B.STATE, B.POSTAL, B.RELATIONSHIP, A.DEPTID, A.JOBCODE, A.COMPANY, A.EMPL_TYPE
    FROM (PS_EMPLOYEES A LEFT OUTER JOIN PS_EMERGENCY_CNTCT B ON A.EMPLID = B.EMPLID ), PS_EMPLMT_SRCH_QRY A1, PS_PERS_SRCH_QRY B1
    WHERE A.EMPLID = A1.EMPLID
    AND A.EMPL_RCD = A1.EMPL_RCD
    AND A1.OPRID = 'SREESR'
    AND (B.EMPLID = B1.EMPLID OR B.EMPLID IS NULL )
    AND B1.OPRID = 'PS'
    Appreciate any help.

    I think there are fixes for this issue in later tools releases (Report ID 1544345000). I'm not sure about 8.48, but you might try the workaround documented in
    E-QR: Left Outer Joins with Security Records are returning unexpected results [ID 651252.1]
    on Oracle Support.
    Regards,
    Bob

  • Outer Join Two tables

    I got two Tables.APPROVAL_ROUTING_TAB and doc_issue_tab where APPROVAL_ROUTING_TAB has more rows. I need to do the join two tables such that All the rows in APPROVAL_ROUTING_TAB should be displayed ( more rows) but still connect with the doc_issue_tab. I did an outer join syntax failed.
    What is the correct syntax for this.
    Key_ref takes the following pattern "DOC_CLASS=PR_CLASS_1^DOC_NO=1000007^DOC_REV=A3^DOC_SHEET=1^"
    SELECT
    ar.line_no LINE_NO,
    ar.step_no STEP_NO,
    ar.lu_name LU_NAME,
    ar.key_ref KEY_REF,
    ar.description DESCRIPTION,
    di.status STATUS
    FROM APPROVAL_ROUTING_TAB ar, doc_issue_tab di
    WHERE
    ar.key_ref = 'DOC_CLASS='||di.doc_class||'^DOC_NO='||di.doc_no||'^DOC_REV='||di.doc_rev||'^DOC_SHEET='||di.doc_sheet||'^') (+)
    Thansk in advance
    Prash

    Other options include:
    with t1 as (select 1 id, 'd1=fred^d2=john^d3=bob^' col2 from dual union all
                select 1 id, 'd1=fred^d2=john^d3=george' col2 from dual),
         t2 as (select 'fred' d1, 'john' d2, 'bob' d3 from dual union all
                select 'jim' d1, 'john' d2, 'bob' d3 from dual)
    select *
    from   t1, (select t2.*, 'd1='||d1||'^d2='||d2||'^d3='||d3||'^' full_col
                from t2) t3
    where  t1.col2 = t3.full_col (+);
            ID COL2                      D1   D2   D3  FULL_COL              
             1 d1=fred^d2=john^d3=bob^   fred john bob d1=fred^d2=john^d3=bob^
             1 d1=fred^d2=john^d3=george                                     
    with t1 as (select 1 id, 'd1=fred^d2=john^d3=bob^' col2 from dual union all
                select 1 id, 'd1=fred^d2=john^d3=george' col2 from dual),
         t2 as (select 'fred' d1, 'john' d2, 'bob' d3 from dual union all
                select 'jim' d1, 'john' d2, 'bob' d3 from dual)
    select *
    from   t1 left outer join t2 on (t1.col2 = 'd1='||d1||'^d2='||d2||'^d3='||d3||'^');
            ID COL2                      D1   D2   D3
             1 d1=fred^d2=john^d3=bob^   fred john bob
             1 d1=fred^d2=john^d3=george             

  • Unable to collapse rows after full outer joining several tables

    All -
    I often do a "full outer join" on numerous tables when I want to report all of the
    contents of all of the tables in one relatively easy to inspect set of output. However,
    now that my "leading" table is missing certain values, my output is definitely not
    what I want.
    Here's a test case:
    drop table test11;
    create table test11 (x number);
    insert into test11 values (1);
    insert into test11 values (3);
    drop table test12;
    create table test12 (x number);
    insert into test12 values (2);
    insert into test12 values (3);
    drop table test13;
    create table test13 (x number);
    insert into test13 values (1);
    insert into test13 values (2);
    drop table test14;
    create table test14 (x number);
    insert into test14 values (2);
    commit;
    select test11.x t11,
    test12.x t12,
    test13.x t13,
    test14.x t14
    from (((test11 full outer join test12 on test11.x = test12.x)
    full outer join test13 on test11.x = test13.x)
    full outer join test14 on test11.x = test14.x);
    And here is the output:
    T11 T12 T13 T14
    1 1
    3 3
    2
    2
    2
    5 rows selected.
    Forgive me if this doesn't appear with a fixed-width font. I
    don't know how to format these postings.
    See rows 3, 4, and 5? My desire is to jam those
    together so that my output is this instead:
    T11 T12 T13 T14
    1 1
    3 3
    2 2 2
    3 rows selected.
    Do you have any idea how to do this? Of course, I'll need to
    apply the solution to the general case so that all
    test cases similar to this are fixed!
    Thanks very much for your time!
    Tom G.

    For anyone who's interested -
    Here is the solution I was able to put together on my own:
    select max(t11) t11, max(t12) t12, max(t13) t13, max(t14) t14 from
    select coalesce(test11.x, test12.x, test13.x, test14.x) ct,
           test11.x    t11,
           test12.x    t12,
           test13.x    t13,
           test14.x    t14
      from (((test11 full outer join test12 on test11.x = test12.x)
                    full outer join test13 on test11.x = test13.x)
                    full outer join test14 on test11.x = test14.x))
    group by ct;And the output:
           T11        T12        T13        T14
                        2          2          2
             1                     1
             3          3
    3 rows selected.Bye,
    Tom G.

  • Multiple Outer join in ORACLE 8.1.6

    Hi ,
    Can anybody suggest me how can i use multiple outer join on one table. I'm using ORACLE 8.1.6.
    I know this version of oracle doesnt support this. But is there anmy other wa\y I can achieve this.
    Thanks amd Regards
    Deependra

    Tricky question - but I went through this about 3 months ago, and found a good thread on here that explains it pretty well.
    check out Re: Outer join a table with two diff table
    You basically will have to create an inline view with one outer join in there, and then a second outer join on the outside. Read through the posts in that thread and it should help!

  • Equi Join and Outer join using outer keyword

    Hi,
    First lets take the create statment for scott schema.
    create table scott.emp_details(empno number, bonus_date date);
    Insert Into Scott.Emp_Details Values(7369, To_Date('01-jan-2013'));
    Insert Into Scott.Emp_Details Values(7499, To_Date('05-jan-2013'));
    Insert Into Scott.Emp_Details Values(7521, To_Date('10-jan-2013'));
    Insert Into Scott.Emp_Details Values(7566, To_Date('01-feb-2013'));
    Insert Into Scott.Emp_Details Values(7654, To_Date('05-feb-2013'));
    commit;lets also consider the basic scott.emp and scott.dept tables
    Now I would like to equi join emp table deptno col with dept table deptno col and left outer join emp table hiredate with emp_details bonus_date and empno col in emp_details can be joined(Equi Join) with empno col of emp table if needed .The outer join has to be placed using the keyword (left/right)outer join
    The select statement can have all the detials of emp table .The requirement may look weird but we have some such requirement.
    Please suggest

    Hi,
    sri wrote:
    Hi,
    First lets take the create statment for scott schema.
    create table scott.emp_details(empno number, bonus_date date);
    Insert Into Scott.Emp_Details Values(7369, To_Date('01-jan-2013'));
    Insert Into Scott.Emp_Details Values(7499, To_Date('05-jan-2013'));
    Insert Into Scott.Emp_Details Values(7521, To_Date('10-jan-2013'));
    Insert Into Scott.Emp_Details Values(7566, To_Date('01-feb-2013'));
    Insert Into Scott.Emp_Details Values(7654, To_Date('05-feb-2013'));
    commit;
    It's best not to create your own tables in Oracle-supplied schemas, such as SCOTT. Use your own schema for your own tables.
    lets also consider the basic scott.emp and scott.dept tablesI see; you're using the standard scott,emp and scott.dept tables, plus the emp_details table you posted above.
    Now I would like to equi join emp table deptno col with dept table deptno col and left outer join emp table hiredate with emp_details bonus_date and empno col in emp_details can be joined(Equi Join) with empno col of emp table if needed .The outer join has to be placed using the keyword (left/right)outer join
    The select statement can have all the detials of emp table .The requirement may look weird but we have some such requirement.
    Please suggestThanks for posting the sample data. Don't forget to post the exact output you want from that sample data.
    Do you want something like this?
    `    EMPNO ENAME          DEPTNO DNAME          BONUS_DAT
          7369 SMITH              20 RESEARCH       01-JAN-13
          7499 ALLEN              30 SALES          05-JAN-13
          7521 WARD               30 SALES          10-JAN-13
          7566 JONES              20 RESEARCH       01-FEB-13
          7654 MARTIN             30 SALES          05-FEB-13
          7698 BLAKE              30 SALES
          7782 CLARK              10 ACCOUNTING
          7788 SCOTT              20 RESEARCH
          7839 KING               10 ACCOUNTING
          7844 TURNER             30 SALES
          7876 ADAMS              20 RESEARCH
          7900 JAMES              30 SALES
          7902 FORD               20 RESEARCH
          7934 MILLER             10 ACCOUNTING
                                  40 OPERATIONSIf so, here's one way to do it:
    SELECT       e.empno, e.ename     -- or whatever columns you want
    ,       d.deptno, d.dname     -- or whatever columns you want
    ,       ed.bonus_date
    FROM           scott.dept  d
    LEFT OUTER JOIN      scott.emp   e   ON  e.deptno     = d.deptno
    LEFT OUTER JOIN      emp_details ed      ON  ed.empno     = e.empno
    ORDER BY  e.empno
    ;

  • Using Left Outer Join

    Hi SAP,
    I have an access database with table called "Employee_ID".  I am linking this table to a table called "Sales" in our main database and trying to report on January 2009.
    There is one employee that is not appearing in my report.  I know this employee has had no sales in Jan 2009.  So, I tried linking the table using Left Outer Join and still this employee is not appearing in my report.
    As a test, when I bring in Employee_ID table alone, the missing employee appears but when I try linking it INNER or LEFT OUTER join to table Sales, this employee does not appear.
    Any help how I can bring the employee in from table Employee_ID?
    Many thanks in advance,
    Zack H.

    Carl & Raghavendra,
    Your suggestion led me to the finding my solution.  Your suggestion brought back the missing employee but I needed all employees that had sales in January 2009 AND those that didn't.  So I had to tweak your select expert formula as follows:
    isnull({Sales.amt}) or
    {Sales.period}="0109"
    This brought back everything as needed!  There was one negative about using this method.  The performance was poor.  It took a really long time to run.
    To avoid having to wait for this to run and increase the performance, I had to go into the database and add a $0.00 sales amt for employee 2040 (or an empty sales amount record) in the month of January 2009.  This brought back everyone also and it obviously increased the performance exponentially.  Curious, why does it take forever to run using the above formula in select expert?
    Thank you both Raghavendra and Carl for your relentless efforts to find a solution.  You did it!
    Zack H.

  • ORA-22922: nonexistent LOB value in outer join in XMLDB parsing query

    Hi,
    We are in a situation where i must use outer join with the address type fragment in the XML reader query,
    Here is the oracle installation details
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    PL/SQL Release 11.2.0.3.0 - Production
    "CORE     11.2.0.3.0     Production"
    However once i add the (+) sign i get an error, other wise it runs absolutely fine without the (+) s
    ORA-29400: data cartridge error
    ORA-22922: nonexistent LOB value
    29400. 00000 - "data cartridge error\n%s"
    *Cause:    An error has occurred in a data cartridge external procedure.
    This message will be followed by a second message giving
    more details about the data cartridge error.
    *Action:   See the data cartridge documentation
    for an explanation of the second error message.
    Query:
    =======
    select
    from PWAYWORKFILE_TABLE,
    xmltable(
    xmlnamespaces(DEFAULT 'http://www.cccis.com/Pathways/Workfile'
    , 'http://www.cccis.com/Pathways/CommonType' as "pct")
    , '$XS/PwayWorkfile' passing WORKFILE as "XS"
    columns
    CURESTID VARCHAR2 (4000) PATH 'EstimateComp/LastOutboxEstID',
    Est_Fragment XMLTYPE PATH 'EstimateComp/EstList/VehEstimate'
    ) m,
    XMLTABLE(
    xmlnamespaces(DEFAULT 'http://www.cccis.com/Pathways/Workfile'
    , 'http://www.cccis.com/Pathways/CommonType' as "pct")
    , '$PY/VehEstimate' passing m.Est_Fragment as "PY"
    columns
    NUMBERLINES VARCHAR2 (4000) PATH '@NumberLines',
    LINEESTIMATEID VARCHAR2 (4000) PATH 'EstimateID',
    EstLine_Fragment XMLTYPE PATH 'EstimateLines/EstimateLine'
    ) (+) l,
    XMLTABLE(
    xmlnamespaces(DEFAULT 'http://www.cccis.com/Pathways/Workfile'
    , 'http://www.cccis.com/Pathways/CommonType' as "pct")
    , '$NY/EstimateLine' passing l.EstLine_Fragment as "NY"
    columns
    LINENUMBER VARCHAR2 (4000) PATH '@LineNumber',
    LINEBLOCKID VARCHAR2 (4000) PATH 'LineBlockID',
    LABORCATEGORY VARCHAR2 (4000) PATH 'LaborCategory',
    LABORHOURS VARCHAR2 (4000) PATH 'LaborHours',
    LINEOPERATION VARCHAR2 (4000) PATH 'LineOperation',
    MANUALLABORINCLUDE VARCHAR2 (4000) PATH 'ManualLaborInclude',
    MANUALPAINTINCLUDE VARCHAR2 (4000) PATH 'ManualPaintInclude',
    MANUALPRICEINCLUDE VARCHAR2 (4000) PATH 'ManualPriceInclude',
    OEMPRICE VARCHAR2 (4000) PATH 'Calculation/OEMPrice',
    SINGLEOHINCL VARCHAR2 (4000) PATH 'DataList/DBMotorData/LaborInclType/@SINGLEOHINCL',
    DOUBLEOHINCL VARCHAR2 (4000) PATH 'DataList/DBMotorData/LaborInclType/@DOUBLEOHINCL',
    PPAGEINCL VARCHAR2 (4000) PATH 'DataList/DBMotorData/LaborInclType/@PPAGEINCL',
    SUPPLIERID VARCHAR2 (4000) PATH 'DataList/RPSPart/SupplierID'
    ) (+) j
    where
    l.LINEESTIMATEID = 51 or
    l.LINEESTIMATEID = m.CURESTID or
    l.LINEESTIMATEID = (CASE
    WHEN m.CURESTID = 101 THEN 51
    WHEN m.CURESTID > 101 THEN m.CURESTID -1
    ELSE -1 END);
    Please note that the PWAYWORKFILE_TABLE is objection relationally stored with XMLs.
    Please suggest what kind of error i am getting and what possible steps might resolve the same, let me know if i missed any details which might shade more light on the same.
    Regards,
    Arghyadip

    Which outer join gives you the error? I don't see any address information in the SQL, hence my question. The first outer join, on table alias L is not needed. The WHERE clause you have setup requires that L.LINEESTIMATEID has a value and so NULL will not evaluate to TRUE and the row will be filtered out. This means you will only be returning rows where there exists rows in the L table, hence the outer join is not needed.
    Are all your columns really VARCHAR2(4000)? You say it is object-relational, but was something defined as a CLOB?
    You did not provide much in order to duplicate your error so I am just guessing at causes to identify the error.
    Also see #9 in
    {message:id=9360002}

  • Outer join with additional constraint

    Hi,
    Using Oracle 11g R2.
    I'd like to outer join 2 tables together and place a restrictions on the types of records which should be returned in the query result. Here is a mock up of the tables and data.
    create table aaa (col1 number not null, col2 number not null)
    create table bbb (col1 number not null, col2 number not null)
    insert into aaa values (1, 80)
    insert into aaa values (2, 90)
    insert into aaa values (3, 80)
    insert into aaa values (4, 90)
    insert into aaa values (5, 80)
    insert into bbb values (3, 600)
    insert into bbb values (4, 700)
    Here's the query
    select a.col1, a.col2, b.col1, b.col2
    from aaa a, bbb b
    where a.col1 = b.col1 (+)
    and   (a.col2, b.col2) <> ((90, 700))
    The query result shows as follows.
    col1 col2 col1 col2
    1     80 
    3     80    3 600
    5     80 
    Where col1 = 4 has been removed which is an expected result. However, where col1 = 2 has also been removed, which is not a desired result. Your response is appreciated.

    arizona9952 wrote:
    Thanks. Any reason for the NVL in
    NVL (a.col2, 0)  <>  90
    NVL (a.col2, 0)  <>  90 is not needed. When we outer join to non-existing b.col1 = 2 we get NULL b.col2. Result of (90,null) <> (90,700) is NULL, not TRUE. Frank's solution assumes b.col2 can't be 0, so he uses 0 in NVL to force TRUE instead of NULL. If b.col2 can be any value, use:
    select  a.col1,
            a.col2,
            b.col1,
            b.col2
      from      aaa a
            left join
                bbb b
              on (
                      a.col1 = b.col1
      where (a.col2,b.col2) <> ((90,700))
         or b.col2 is null
          COL1       COL2       COL1       COL2
             3         80          3        600
             5         80
             1         80
             2         90
    SQL>
    SY.
    Message was edited by: Solomon Yakobson

Maybe you are looking for

  • Mystery Monitor

    Hey now... For awhile, I had a second monitor hooked up and used for dual screen Final Cut editing sessions. When I wanted to add text, I would use Boris Title 3D and "Click for Options" which opens a new window that I can type my text into. (Stay wi

  • Only Part of Music Library Home Shared

    Is there any obvious explanation for why only 51 of my 293 albums show up on iPad 2 using Home Sharing?

  • After unpairing a device I cannot pair it again

    I successfully paired my 4S to our Polk sound bar. After getting frustrated because I couldn't get the soundbar to work with the TV again, I unpaired my phone. Now when I try to pair it again, it appears in my Bluetooth window but the pairing is alwa

  • Can't make or receive calls  - Motorola Razr Maxx

    My wife and I can not make or receive calls on our Motorola Razr Maxx phones.  We can receive and send texts.   We have turned off our phones and restarted to no avail.  We are in the Metro Atlanta area. Any ideas or suggestions?

  • How to close a window in a jsp page ??

    Hi........I 've created an application in JSPDynpage. In my JSP Page i've a close button .On click of the "close" button , the window has to close. How can i achieve this . Please provide me some solutions. Thanks Smita