Left Outer Join on same table clarification

HI,
I have a table that gets populated from 3<sup>rd</sup> party system. We don’t have control over it. So, the table has master record (master) and children. Master type is 78 and children’s type is 64. So, it looks like this. In the 3<sup>rd</sup>
party system, if Master transaction gets cancelled, it is recorded as type 178. If child is cancelled, then it is 164. Once the child is cancelled and created again using one process then newly created transaction will have 65 as type. Same thing with Master
cancelled transaction also. It will be 79. So, to summarize:
Master:                                                                                                                                                                      
Brand New Transaction type = 78
Cancelled Transaction type = 178
Cancelled with creation transaction type = 79
Child:
Brand New Transaction type = 64
Cancelled Transaction type = 164
Cancelled with creation transaction type = 65
I don’t have to bother about master records. I need to focus on only children for my query.
ID
TxnID
Master
Type
TDate
Location
193075
211554
211543
64
20140805
ABC
193076
211555
211543
64
20140805
NBC
193077
211556
211543
64
20140805
ABC
193080
211559
211558
64
20140805
ABC
193081
211562
211561
64
20140805
ABC
193082
211565
211564
64
20140805
CBC
193083
211565
211564
164
20140805
CBC
193084
211566
211564
65
20140805
AZC
--drop
table #Transactions
CREATE
TABLE #Transactions
ID
int,
TxnID
int,
mstTicket
int,
Typecode
int,
Tdate
datetime,
Location
varchar(10)
select
* from
#Transactions
Insert
into #Transactions
(ID,
TxnID,
mstTicket,Typecode,Tdate,Location)
Select 193075, 211554,211543,64,'2014-08-05','ABC'
UNION ALL
Select 193076, 211555,211543, 64,
'2014-08-05',
'NBC' UNION ALL
Select 193077, 211556, 211543, 64,
'2014-08-05',
'ABC' UNION
ALL
Select 193080, 211559, 211558, 64,
'2014-08-05',
'ABC' UNION
ALL
Select 193081, 211562, 211561, 64,
'2014-08-05',
'ABC' UNION
ALL
Select 193082, 211565, 211564, 64,
'2014-08-05',
'CBC' UNION
ALL
Select 193083, 211565, 211564, 164,
'2014-08-05',
'CBC' UNION
ALL
Select 193084, 211566, 211564, 65,
'2014-08-05',
'AZC'
select
T.TxnID,
T.TypeCode,
T.Location,
TL.TxnID
From
#Transactions T
Left Outer
JOIN #Transactions
TL ON
TL.TxnID
= T.TxnID
and TL.TypeCode
= 164
select
T.TxnID,
T.TypeCode,
T.Location,
TL.TxnID
From
#Transactions T
Left Outer
JOIN #Transactions
TL ON
TL.TxnID
= T.TxnID
and TL.TypeCode
= 164
Where
T.typecode
in (64, 65)
I need a clarification regarding left Outer Join. 
In the first left outer join query both 64 and 164 both have TL.TxnID populated. Why is that?. What I understand from
left outer join is that ‘Returns all the rows’ from left table and only matching data from right table.
Here, matching row from right table is 211565 and 164 record (id 193083). So, only it should have TxnID populated. But row 211565 and 64 has TL.txnID getting populated (ID 193082).
Why is it? Am I not understanding left out join properly?
Thanks,

Thank you Shailesh. I understood what join does in left outer join. I was thinking
 Left Outer JOIN #Transactions TL ON TL.TxnID = T.TxnID and TL.TypeCode = 164 is same as
Left Outer JOIN #Transactions TL ON TL.TxnID = T.TxnID and TL.TypeCode = T.TypeCode
and TL.TypeCode = 164
#Transactions
T
Left
Outer
JOIN
#Transactions
TL
ON
TL.TxnID
=
T.TxnID
and
TL.TypeCode
= 164
Where
T.typecode
in
(64,
65)

Similar Messages

  • Left outer join using multiple table

    Hi,
    I am trying to use left outer join with multiple tables , the join condition will be based on  PERNR and BEGDA & ENDA for each infotype in selection screen.
      select pa00~pernr pa00~begda pa00~endda pa00~massn pa00~massg pa00~stat2 pa00~aedtm pa00~uname
        pa01~begda pa01~endda pa01~bukrs pa01~persg pa01~persk pa01~mstbr pa01~ename pa01~aedtm pa01~uname
        pa02~begda pa02~endda pa02~nachn pa02~vorna pa02~midnm pa02~aedtm pa02~uname
        pa016~begda pa016~endda pa016~cttyp pa016~aedtm pa016~uname
        into CORRESPONDING FIELDS OF TABLE i_pall
        from  ( PA0000 as pa00 left OUTER JOIN pa0001 as pa01 on pa00~pernr = pa01~pernr )
        left OUTER JOIN pa0002 as pa02 on pa00~pernr eq pa02~pernr )
        left OUTER JOIN  pa0016 as pa016 on pa00~pernr eq pa016~pernr )
        where pa00~pernr in S_pernr
        AND pa00~begda in s_bg0000
        and pa00~endda in s_nd0000.
    but this fails  to fetch the value of begda enda from each pa0000,pa0001,pa0002,pa0016.
    Please help!
    Monirul

    Why don't you use the standard logical database PNPCE and then Provide statement?

  • Case statement resulting into Left outer join with other tables

    Hi All ,
    I am facing a stuation where a Case statement on one of the logical columns in Answers is resulting into a left outer join with a table in the query.
    If we remove the case stmt, the table is not being acessed.
    The case stmt is a simple one and no other logical column is being accessed in the case stmt.
    Please advice .
    Thanks.

    Hi Sai,
    No ..we dont have any left outer join ...its just that I am selecting measure from F1 which has a confimred dimension D1 with F2.Now when I dont have case stmt on measure from F1(Case stmt is something like : CASE WHEN "- P table"."P Column" = 'Y' THEN 'Right' ELSE 'Wrong' END), then it doesnt query F2.
    However as soon as I introduce the case stmt ,the query creates a left outer join with F2.
    Thanks.

  • 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

  • Restriction to Left Outer Joins in PS Query

    Hello I am trying to do Left Outer JOin in PS QUERY. I need to do dept tbl, job code tbl and locatable as left outer joins with JOB Table. Looks like in PS QUERY there is a error message saying as below. Can someone has any workaround to achieve this in PS QUERY. I know I can create a View and use that in PS QUERY but BUsiness Users are dependent on IT, so that doesn't work. Also, adding JOB table multiple times works but I am looking for better solution if anyone had come accorss working through PS QUERY Outer JOins.
    Windows Internet Explorer
    Left outer joins must be joined to the last record in the query. (139,290)
    OK
    Thanks,
    SC.

    Hi Mike,
    According to your description, you want to improve the performance for your DAX query in SQL Server Analysis Service Tabular model, right? Here is a white paper describes strategies and specific techniques for getting the best performance from your tabular
    models, including processing and partitioning strategies, DAX query tuning, and server tuning for specific workloads.
    http://msdn.microsoft.com/en-us/library/dn393915.aspx
    Since this is a complex DAX query, from a support perspective this is really beyond what we can do here in the forums. If you cannot determine your answer here or on your own, consider opening a support case with Microsoft. Visit this link to see the various
    support options that are available to better meet your needs:
    http://support.microsoft.com/default.aspx?id=fh;en-us;offerprophone
    Regards,
    Charlie Liao
    TechNet Community Support

  • How to do left outer join in one-one mapping

    I tried to do a left outer join between two tables. I specified
    kodo.jdbc.DBDictionary: JoinSyntax=sql92 in kodo.properties. I used
    ref-join-type="outer" in the package.mapping. However, I still see Kodo is
    translating my queries using inner join. How can I force kodo to use outer
    join (or maybe even to use left outer join) when translating my queries?
    Thanks.

    Kodo will automatically use an outer join when eager-fetching a to-one
    relation (unless you have set null-value="exception" on the field, in
    which case Kodo knows it can use an inner join). There is no need to set
    the ref-join type (in fact, that is only for when the foreign key
    columns are in a joined table).
    When you place criteria on a relation in a query, though, the relation
    must exist to satisfy the query. For example, in the filter:
    "relation.x == y"
    The "relation" field must hold a related object to satisfy the
    expression, just as in Java.
    If you want the "relation" field to optionally be null, then write your
    filter exactly as you would in Java:
    "relation == null || relation.x == y"
    Kodo will correctly use an outer join in this case because the filter
    can be satisfied even when no related object exists.

  • Oracle 8i -multiple LEFT OUTER JOIN

    Hi,
    I have to convert some stored procedure from Sql Server to Oracle 8i where I have multiple LEFT OUTER JOIN on a table. Because Oracle 8i accept only one outer join on a table how can I convert this:
    select a.id, b.id
    from test as a LEFT JOIN test1 b ON a.id(+)=b.id
    and a.display(+)=b.display
    and a.name(+)='Done';
    Thanks.

    FROM test a LEFT JOIN test1 b ON b.key = a.keyis equivalent to
    FROM test a, test1 b WHERE b.key(+) = a.keyThere is a restriction (when using the "(+)" syntax) that a table may be outer-joined to at most one other table, but that does not prevent you from having multiple join conditions between those two tables.
    From your example I'm not sure whether you need this:
    SELECT a.id, b.id
    FROM   test a
         , test1 b
    WHERE  a.name = 'Done'
    AND    b.id (+)= a.id
    AND    b.display (+)= a.display;or this:
    SELECT a.id, b.id
    FROM   test1 b
         , test  a
    WHERE  a.id (+)= b.id
    AND    a.display (+)= b.display;
    WHERE  a.name (+)= 'Done';

  • Issue on left outer join query in 10G

    Dear Mr./Mrs./Ms. Oracle expertise,
    The following query structure can function properly in Oracle 9i, but not work in Oracle 10G.
    Please kindly advise what happened in Oracle 10G?
    Is it a bug in 10G? If yes, any patch for it?
    select a.col1,
    a.col2,
    a.col5,
    b.col3,
    b.col4
    from t1 a
    inner join t2 c on c.col1 = a.col1
    left join (select col3
    col4
    from t3) b
    on b.col1 = a.col1
    and a.col2 = 'Y' <---------- seems 10G cannot allow this condition
    where a.col5 = 123;
    Purpose of above SQL
    ====================
    Only those records from t1 table with a.col2 = 'Y' will
    do the left outer join to "b" table and get the columns b.col3 and b.col4
    Result set in Oracle 9i
    =======================
    col1 col2 col5 col3 col4
    AAA N 111
    BBB N 222
    CCC Y 333 XYZ OOO
    DDD Y 444 QPR 111
    Result set in Oracle 10G
    ========================
    col1 col2 col5 col3 col4
    AAA N 111
    BBB N 222
    CCC Y 333
    DDD Y 444
    Rgds,
    Ken Chan

    Dear Schneider,
    Sorry that there was a typo in my query.
    Below is the revised query.
    select a.col1,
    a.col2,
    a.col5,
    b.col3,
    b.col4
    from t1 a
    inner join t2 c on c.col1 = a.col1
    left join (select col1,
    col3,
    col4
    from t3) b
    on b.col1 = a.col1
    and a.col2 = 'Y' <---------- seems 10G cannot allow this condition
    where a.col5 = 123;
    Thanks.
    Rgds,
    ken Chan

  • Error in making left outer join to a nested query

    i am writing this query getting error here i am using nested query with that i am making join it is giving error
    SQL
    SELECT
    * FROM IVItem INNER JOIN
    IVPackSize_Mst ON IVItem.PackSizeID = IVPackSize_Mst.Id
    left outer join IvItemGenericLink on IvItemGenericLink.itemID=IVItem.Id
    Select GenericId from
    IvItemGenericLink where ItemID=IVItem.Id and rownum <=1
    )x
    and x on IvItemGenericLink.GenericId=x.GenericId;
    Error report:
    SQL Error: ORA-00936: missing expression
    00936. 00000 - "missing expression"
    *Cause:   
    *Action:
    give me and suggestion

    i am using left outer join at virtual table say x your gave me its equivalent
    EXISTS (SELECT 1 FROM IvItemGenericLink G
    WHERE G.ITEMID =V.ID
    AND G.GenericId = L.GenericId)-----its i guess inner join
    i am not confirmed that why iam asking this i guess i have to use this
    as i use keyword inner join for inner join and for left join i use
    left outer join
    EXISTS (SELECT 1 FROM IvItemGenericLink G
    WHERE G.ITEMID =V.ID
    AND G.GenericId(+) = L.GenericId)-----its i guess left outer join
    left outer join
    Select GenericId from
    IvItemGenericLink where ItemID=IVItem.Id and rownum <=1
    )*x*
    IvItemGenericLink.GenericId=x.GenericId
    -------------------Statement U Gave in this--------------------------------------------------------------------------
    SELECT *
    FROM IVITEM V, IVPACKSIZE_MST M , IVITEMGENERICLINK L,
    WHERE V.PACKSIZEID = M.ID
    AND V.ID = L.ITEMID (+)
    AND EXISTS (SELECT 1 FROM IvItemGenericLink G
    WHERE G.ITEMID =V.ID
    AND G.GenericId = L.GenericId)
    -------------------Statement U Gave in this--------------------------------------------------------------------------
    is this equivalent to left outer join
    *AND EXISTS (
    SELECT 1 FROM IvItemGenericLink G*
    WHERE G.ITEMID =V.ID
    *AND G.GenericId = L.GenericId
    please tell me this in this regard

  • Left Outer Join in BMM layer

    Hi All,
    while building the RPD we have to use the join as Left outer join for two tables , we added join condition in BMM layer like evey table we have three tabs like General,Column Maooing and Content.
    In General tab we have to sections like map to these tabls and Joins right. In the Join Scetion we add join conditions for two tables as left outer join.
    Now i need to move the first table as second table and wise versa , how i can?? move these two tables
    Thanks for your help.

    Hi User,
    You will have to remove and add the table as there is no option to reorder the tables.
    Rgds,
    Dpka

  • Multiple LEFT OUTER JOIN on Oracle 8i

    Hi,
    I have to convert some stored procedure from Sql Server to Oracle 8i where I have multiple LEFT OUTER JOIN on a table. Because Oracle 8i accept only one outer join on a table how can I convert this:
    select a.id, b.id
    from test as a LEFT JOIN test1 b ON a.id(+)=b.id
    and c.display(+)=b.display
    and c.name(+)='Done';
    Thanks.

    Rewrite as:
    select a.id, b.id
    from test, test1 b
    WHERE a.id(+)=b.id
    and a.display(+)=b.display
    and a.name(+)='Done';
    Though I would lose the (+) in a.name(+) = 'Done' unless you want every name.

  • Tuning a left outer join

    Hello All,
    Good Afternoon!! Thought I will post some interesting findings of mine while I was given the task of reviewing and finding tuning scope for some complex pl/sql codes. In one of them, I found a weird way of doing a Left Outer Join against a table and they haven't used any hints typically used for joining operations (such as Ordered), but instead they used a Parallel with a table alias to the driven table, which I think is being rendered useless when it runs. This is what it looks like -
    SELECT /*+ PARALLEL(V) */ DISTINCT
             CASE WHEN y.u_dc_run_op IS NOT NULL THEN 1
             ELSE 0 END
        FROM (select 1 sw from dual) x
                LEFT OUTER JOIN
                   (SELECT V.U_DC_RUN_OPT, v.u_dc_run_pend
                      FROM dview v, u_dc_process_ctrl u
               WHERE v.u_dc_run_opt = u.opt
                AND  v.u_dc_run_pend = 1
                AND  u.process_wk = (TO_CHAR(SYSDATE,'WW') + 0)
                AND  TRIM(v.u_dc_run_opt) IS NOT NULL) y
                    On x.sw = y.u_dc_run_pend;
    Oracle is running on - Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production.
    The inner table itself is a result of another join against a 100M heavy table with another 100K light table (see below for their table definitions). Cost of the above query and Explain Plan results are as below -
    PLAN_TABLE_OUTPUT
    SQL_ID 0rpsxqtvvcmsx, child number 0
    SELECT /*+ PARALLEL(V) */ DISTINCT          CASE WHEN
    y.u_dc_run_op IS NOT NULL THEN 1          ELSE 0 END     FROM
    (select 1 sw from dual) x             LEFT OUTER JOIN
    (SELECT V.U_DC_RUN_OPT_SET, v.u_dc_run_pend FROM
    dview v, u_dc_process_ctrl u            WHERE v.u_dc_run_opt =
    u.opt AND v.u_dc_run_pend = 1             AND
    u.process_wk = (TO_CHAR(SYSDATE,'WW') + 0)             AND
    TRIM(v.u_dc_run_opt) IS NOT NULL) y On x.sw =
    y.u_dc_run_pend
    Plan hash value: 49153038
    | Id  | Operation | Name | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
    | 0 | SELECT STATEMENT | |       | |  1444K(100)| |       |       |
    | 1 |  HASH UNIQUE | |     1 |    19 |  1444K  (3)| 00:01:55 | |       |
    | 2 |   NESTED LOOPS OUTER | |     1 |    19 |  1444K  (3)| 00:01:55 | |       |
    | 3 |    TABLE ACCESS FULL            | DUAL |     1 |     2 |     3   (0)| 00:00:01 |       |       |
    |* 4 |    VIEW | |     1 |    17 |  1444K  (3)| 00:01:55 | |       |
    |* 5 |     HASH JOIN | |     1 |   122 |  1444K  (3)| 00:01:55 |       |       |
    | 6 |      TABLE ACCESS BY INDEX ROWID| U_DC_PROCESS_CTRL    |     1 | 115 |     0 (0)| |       |       |
    |* 7 |       INDEX RANGE SCAN          | U_DC_PROCESS_CTRL_PK |     1 |       |     0 (0)| |       |       |
    | 8 |      PARTITION HASH ALL         |                      | 283K|  1937K|  1444K  (3)| 00:01:55 |     1 |    64 |
    |* 9 |       TABLE ACCESS FULL         | DVIEW |   283K|  1937K|  1444K  (3)| 00:01:55 |     1 |    64 |
    Predicate Information (identified by operation id):
    4 - filter("Y"."U_DC_RUN_PEND"=1)
    5 - access("V"."U_DC_RUN_OPT"="U"."OPT")
    7 - access("U"."PROCESS_WK"=TO_NUMBER(TO_CHAR(SYSDATE@!,'WW'))+0)
    9 - filter(("V"."U_DC_RUN_PEND"=1 AND TRIM("V"."U_DC_RUN_OPT") IS NOT NULL))
    SQL_ID 0rpsxqtvvcmsx, child number 1
    SELECT /*+ PARALLEL(V) */ DISTINCT          CASE WHEN
    y.u_dc_run_opt IS NOT NULL THEN 1          ELSE 0 END     FROM
    (select 1 sw from dual) x             LEFT OUTER JOIN
    (SELECT V.U_DC_RUN_OPT, v.u_dc_run_pend FROM
    dview v, u_dc_process_ctrl u            WHERE v.u_dc_run_opt =
    u.opt AND v.u_dc_run_pend = 1             AND
    u.process_wk = (TO_CHAR(SYSDATE,'WW') + 0)             AND
    TRIM(v.u_dc_run_opt) IS NOT NULL) y On x.sw =
    y.u_dc_run_pend
    Plan hash value: 49153038
    | Id  | Operation | Name | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
    | 0 | SELECT STATEMENT | |       | | 1444K(100)| |       |       |
    | 1 |  HASH UNIQUE | |     1 |    19 |  1444K  (3)| 00:01:55 | |       |
    | 2 |   NESTED LOOPS OUTER | |     1 |    19 |  1444K  (3)| 00:01:55 | |       |
    | 3 |    TABLE ACCESS FULL            | DUAL |     1 |     2 | 3   (0)| 00:00:01 | |       |
    |* 4 | VIEW | |     1 |    17 |  1444K  (3)| 00:01:55 | |       |
    |* 5 |     HASH JOIN | |     1 |   122 |  1444K  (3)| 00:01:55 |       |       |
    | 6 |      TABLE ACCESS BY INDEX ROWID| U_DC_PROCESS_CTRL    |  4069 | 456K|     0 (0)|          | |       |
    |* 7 |       INDEX RANGE SCAN          | U_DC_PROCESS_CTRL_PK |     1 |       |     0 (0)| |       |       |
    | 8 |      PARTITION HASH ALL | |  5459K|    36M|  1444K  (3)| 00:01:55 |     1 |    64 |
    |* 9 |       TABLE ACCESS FULL         | DVIEW |  5459K|    36M|  1444K  (3)| 00:01:55 |     1 |    64 |
    Predicate Information (identified by operation id):
    4 - filter("Y"."U_DC_RUN_PEND"=1)
    5 - access("V"."U_DC_RUN_OPT"="U"."OPT")
    7 - access("U"."PROCESS_WK"=TO_NUMBER(TO_CHAR(SYSDATE@!,'WW'))+0)
    9 - filter(("V"."U_DC_RUN_PEND"=1 AND TRIM("V"."U_DC_RUN_OPT") IS NOT NULL))
    Note
    - cardinality feedback used for this statement
    Here's the syntax how DView and u_dc_process_ctrl tables are created -
    CREATE TABLE "A"."DVIEW"
       ( "DUNIT" VARCHAR2(50 CHAR),
      "DGROUP" VARCHAR2(50 CHAR),
      "LOC" VARCHAR2(50 CHAR),
      "U_DC_RUN_OPT" VARCHAR2(50 CHAR) DEFAULT ' ',
      "U_DC_RUN_PEND" NUMBER(1,0) DEFAULT 0
    Please note that we have DView with 64 partitions on DUNIT as a key. Approximate volume of DVIEW is about 100M.
    CREATE TABLE "A"."U_DC_PROCESS_CTRL"
       ( "PROCESS_WK" NUMBER(2,0),
      "PROCESS_LVL" VARCHAR2(10 CHAR),
      "ASSRT" VARCHAR2(50 CHAR),
      "ITEM" VARCHAR2(50 CHAR),
      "CNTRY" VARCHAR2(50 CHAR),
      "OPT" VARCHAR2(50 CHAR),
      "PROCESS_DT" DATE,
      "EXCEPTION" VARCHAR2(255 CHAR) DEFAULT ' '
    U_DC_PROCESS_CTRL is a non-partitioned table and has less than 10k records in it.
    The problem is, this apparently simple query is running for 26 minutes and I think we can avoid doing the outer join or use an ORDERED hint instead of a PARALLEL hint to the query.
    Appreciate any inputs to the above. Thanks much!!
    Thanks,
    Sanders.

    I'm looking directly at your first plan output.  The highlighted columns don't match.
    SQL_ID 0rpsxqtvvcmsx, child number 0
    SELECT /*+ PARALLEL(V) */ DISTINCT         
    CASE WHEN y.u_dc_run_op IS NOT NULL
    THEN 1         
    ELSE 0
    END    
    FROM (select 1 sw from dual) x            
    LEFT OUTER JOIN (SELECT V.U_DC_RUN_OPT_SET, v.u_dc_run_pend
    FROM    
    Forget that for now.  You say the query runs in 26 minutes.  I don't know if that's good or bad.  You're joining to a table with 100 million rows and 64 partitions and then doing a distinct on the results.  Depending on your hardware, the load, etc. that might not be too bad.
    Also...what's the business logic for this query?  The only column returned is a case statement that can only result in 0 or 1.  And then a distinct is applied to that, so at most this query can return 2 rows.  How many rows would it return without the distinct?  Joining to dual is a little weird but I guess whoever coded this wanted to guarantee at least 1 row returned.  Are the cardinality estimates correct?
    > and they haven't used any hints typically used for joining operations
    That's good.  Typically you should never use hints like this in production code.  They are poison.

  • 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

  • OJ syntax for multi-table left outer join with MS Oracle Driver

    I have a multi-table left outer join that works fine in SQL Server ODBC Driver, Oracle ODBC driver 8.01.07.00, but not with Microsoft ODBC Driver for Oracle 2.573.7326.0
    SELECT * from { oj A LEFT OUTER JOIN B ON A.col1 = B.col1 LEFT OUTER JOIN C ON A.col1 = C.col1 }
    I noticed someone had a similar problem (the proposed solution doesn't work):
    http://www.justpbinfo.com/listarchive/msg02874.html
    Does anyone know how to get this working with the Microsoft ODBC Driver for Oracle? Or does it just not work?

    The Microsoft ODBC Driver for Oracle 2.573.7326.0 does perform the same 'fix up' with {oj} in Oracle 8i. The problem is that it doesn't work when joining more than two tables:
    This works:
    SELECT * from { oj A LEFT OUTER JOIN B ON A.col1 = B.col1}
    This doesn't work:
    SELECT * from { oj A LEFT OUTER JOIN B ON A.col1 = B.col1 LEFT OUTER JOIN C ON B.col1 = C.col1 }
    (The second query will work with the Oracle Oracle ODBC driver, with a bit of tweaking. But I haven't found a way to get it to work with the Microsoft ODBC Driver for Oracle 2.573.7326.0. My suspicion is that it just doesn't work.)
    Gavin

  • How to use left outer join on more than one table (source)

    Hi all,
    In our project we are converting the Unix shell & SQL scripts into OWB mappings. We are facing problem converting left outer join in OWB. here is one of the example. i have just pasted the FROM and where condition.
    FROM ym_scr t1, branch_finmonth t3
    LEFT OUTER JOIN item_image t2
    ON (t1.branch_no = t2.branch_no
    AND t1.item_no = t2.item_no
    AND t3.to_date between t2.tran_dt and t2.to_dt
    AND t2.to_dt >= '$start_images' ) <<<========= '$start_images' THIS COMES FROM THE UNIX VARAIBLE ,
    We converts the same when we are putting it in OWB join Operator
    INGRP1.branch_no = INGRP2.branch_no(+)
    AND INGRP1.item_no = INGRP2.item_no(+)
    AND INGRP3.to_date between t2.tran_dt and t2.to_dt
    AND INGRP2.to_dt >= INGRP2.start_images
    But as you see in the OWB opreator we can put left join with INGRP1 with INGRP2.
    We can not make same join with INGRP3 & INGRP4 , becoz it failed saying "you cannot left outer join on more than one table/source".
    so overall this OWB code makes incomplete left outer join as per the above ANSI SQL join in Oracle.
    Bcoz of the problem we are getting less number of rows...........
    SO please please help me on this
    Regards
    Ashok

    Hi.
    I know this topic is here for a while now, but I had the same problem today, searched for help and didn´t find anything.
    Later I figured out how to do this.
    You just have to put the (+) one time, and the OWB converts in an LEFT OUTER JOIN statement.
    For this case, all you have to do is:
    ( INGRP1.branch_no = INGRP2.branch_no(+) AND INGRP1.item_no = INGRP2.item_no AND INGRP2.to_dt >= INGRP2.start_images )
    Regards,
    Godoy

Maybe you are looking for