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

Similar Messages

  • 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 Join with more than two tables in both CR 8.5 and XIR2

    I am trying to create a report and I have tried two versions of Crystal but I ultimately need the report in CR8.5 for compatibility with the client's system.  I think I am starting to figure out what might be wrong and it might be my understanding of SQL, but I can't see why someone hasn't needed this in the past. Ultimately I want to see all projects and any journal entry that might be posted for that project.
    Database is MySQL 5.0.38 and using MySQL ODBC driver 3.51.19.
    Project header table information will be populated. Each line item on a journal entry can be tagged with the project ID. But for me to pull the journal entry date I need also to link to a third table for the journal entry header info.
    I want to see all projects, whether a journal entry has been posted or not.
    So the links are like this
    ProjectHeader --->Left Outer Join ---> JELines ---> Inner Join ---> JEHeader
    I think in this scenerio Crystal is treating the LOJ as an IJ.
    I created two brand new reports today, one in CR8.5 and one in CR XIR2. Once I edited the automatic CR8.5 SQL statement (which I have been doing for years, usually without problem), they both ran properly. I linked customers to their invoices. Customers without invoices showed properly. But then I linked the invoices to the payments of the invoices and immediately lost customers without orders in both reports.
    So apparently only two tables are allowed in Outer Joins. Does this make sense?  I checked out the w3schools tutorial on SQL and it doesn't mention this limitation and I can't find anywhere else that it specifically indicates this but all samples of code I have seen only show two tables.  I just thought for presentation as a sample that was easiest to understand and we could expand as necessary.
    If this is correct, how does one go about accounting for this kind of thing?  One solution that goes through my mind is creating a view at the database level for the link between journal entry lines and journal entry headers.  Would this be a good solution under normal circumstances?
    A second option that I had to implement because of timelines, is to use a subreport linked to the main report through the project ID to pull the information for the journal entries and just pass the totals I need to the main report through a shared variable.
    These aren't normal circumstances because I don't have access to the database so I can't create the view.  I have come across this concept several times and I have been able to use subreports to solve it but I am trying to find a better solution for the future as sometimes subreports can be slow.  So are there any alternatives I have not considered here?
    TIA rasinc

    So after some more work and another post.  I was able to get this to work.
    Items disappear when linking to another table
    My issues were two fold.  I was selecting on the tables on the right-side of the original Inner Join.  However, I was checking for Nulls.  This apparently is correct but you must check for the Nulls first eg. (IsNull (JEHeader.Field1) OR JEHeader.Field1 <= 100).  I had my original statement reversed checking for <= 100 before checking for Nulls.
    I also did not set all links to be Left Outer Join.  I had the Inner Join.  I actually have about 6 tables in this report so all the links need to be set Outer Join.  So this now seems to be corrected.
    Thanks

  • Left outer join Bug? Oracle 11 g.

    Hi , I am facing a strange problem in oracle 11 g .
    I have a select query like this
    Query 1 :
    Select A.name, B.name, C.name from A Left outer join B on A.id = B.id left outer join C on b.id = c.id and (Some complex condition) left outer join D on C.id = D.id;
    A, B, C, D are tables.
    (Assume that I have data which satisfies the above join conditions)
    However I am not getting C.name in the result. Getting NULL in C.name.
    Now if I add a where clause to the above query like the following Query 2 then I get C.name in the results
    Consider that there is a field called field1 in table C and the value of field1 is ‘xyz’ for all the rows of table C .
    Query 2 :
    Select A.name, B.name, C.name from A Left outer join B on A.id = B.id left outer join C on b.id = c.id and (Some complex condition) left outer join D on C.id = D.id where c.field1 = ‘xyz’;
    I find this strange , What role where clause is playing ? Why I get C.name only after adding where clause.
    I also tried following setting with Query 1 however this also did not help me.
    alter session set "_optimizer_join_elimination_enabled"=false;
    Is oracle does some optimization if no where clause is specified ? Is this a bug?
    Please help me out.
    Thanks,
    Sumit

    874384 wrote:
    ...Is this a bug? Maybe. Maybe not. Really difficult to say based on your description. However, if you suspect a bug, then raise a ticket to the support including much more information (e.g. version 11.x.x.x, define "some condition" and so on).
    Nicolas.

  • LEFT OUTER JOIN with SubQuery

    I have two tables and I want to return all data from the first table with a piece of information from the second based on an effective date being at least a certain value. The tables I am working with contain billions of rows so I need a solution that will also scale.
    Sample tables:
    create table pp ( x number, y number);
    create table ec ( x number, y number, effdate date);
    insert into pp values (1,2);
    insert into pp values (2,3);
    insert into pp values (1,3);
    insert into ec values (1,2,sysdate);
    insert into ec values (2,3,sysdate);
    insert into ec values (1,3,sysdate+365);
    commit;
    select * from pp, ec where pp.x = ec.x(+) and pp.y=ec.y(+)
    and (effdate = ( select max(effdate) from ec ecc where ecc.y=ec.y and ecc.x = ec.x and effdate < sysdate) or effdate is null);
    The above query (and the one below) returns two rows. it does not return where the date does not meet the criteria.
    select * from pp LEFT OUTER JOIN ec ON pp.x = ec.x and pp.y=ec.y
    WHERE (effdate = ( select max(effdate) from ec ecc where ecc.y=ec.y and ecc.x = ec.x and effdate < sysdate) or effdate is null);
    This returns the three rows BUT IS VERY SLOW when run against the billion+ row table (because we cannot correlate the subquery results.)
    select * from pp LEFT OUTER JOIN (SELECT x, y, effdate
    FROM ec WHERE effDate = (SELECT MAX(EFFdate) from ec ecc where ecc.y=ec.y and ecc.x = ec.x and effdate < sysdate)) c ON c.x = pp.x and c.y = pp.y;

    It would help quite a bit to know
    1) your Oracle version
    2) your indexes and data volumes (do BOTH tables have billions of rows?)
    But here's something that may perform faster.
    ME_XE? WITH Maximizied AS
      2  (
      3     SELECT
      4        MAX(EffDate),
      5        x,
      6        y
      7     FROM ec
      8     WHERE EffDate < SYSDATE
      9     GROUP BY x, y
    10  )
    11  SELECT *
    12  FROM pp p, Maximizied m
    13  WHERE p.x = m.x (+)
    14  AND   p.y = m.y (+);
                     X                  Y MAX(EFFDAT                  X                  Y
                     2                  3 05-29-2008                  2                  3
                     1                  2 05-29-2008                  1                  2
                     1                  3
    3 rows selected.
    Elapsed: 00:00:00.03

  • Left outer join with multiple conditions

    Is it possible to add to a left outer join (= anyOfAllowingNone) more than the primary condition (in SQL this would be added per "and").
    Background: The execution plan of the produced SQL shows large results on which the final filter is applied although I have conditions that would decrease this last result set much earlier...

    There is no easy way to do this in TopLink expressions, other than including the join in the regular where clause as you have done. Does it make a big impact in the performance of your query?
    <p>
    You could use custom SQL for the query.
    <p>
    Or you could potentially define a OneToOneQueryKey in your TopLink descriptor that includes the additional join criteria and call anyOfAllowingNone using this query key.
    <p>
    <p>---
    <p>James Sutherland

  • Left outer join with NVL as part of the join criteria

    Hi,
    I have query like this:
    Select
    Main.X_ID,
    NVL(Option1.Y_ID, Option2.Y_ID),
    Main.Z_ID
    from TableMain Main
    left join (Select X_ID, Y_ID from TableOption where type_cd = 'Type1') Option1
    on Main.X_ID = Option1.X_ID
    left join (Select X_ID, Y_ID from TableOption where type_cd = 'Type2') Option2
    on Main.X_ID = Option2.X_ID
    left join TableSub Sub
    on Main.Z_ID = Sub.Z_ID
    and Sub.Y_ID = NVL(Option1.Y_ID, Option2.Y_ID)
    where Sub.Z_ID is null and Sub.Y_ID is null
    Basically i want to show all in Z_IDs TableMain that are not in TableSub where the joining Y_ID is Type1 and if there is not a Y_ID for Type1, then use the Y_ID for Type2.
    The query works if Type1 exists but doesnt if Type1 doesnt and Type2 does.
    Is NVL the correct function to use in the join? Or is there a better way to write such a query?
    Any help would be greatly appreciated. Thanks!!
    FYI all IDs are NUMBERs.

    Hopefully this is easier to understand :)
    Im using 11g.
    DDL and data:
    create table tablemain (
      x_id number (20),
      z_id number (20),
      amount number(20)
    insert into tablemain values (1, 1000, 6767.45);
    insert into tablemain values (1, 1001, 767.45);
    insert into tablemain values (1, 1002, 67.85);
    insert into tablemain values (1, 1003, 997.85);
    insert into tablemain values (2, 1002, 1997.85);
    insert into tablemain values (2, 1004, 197.85);
    insert into tablemain values (2, 1005, 7.85);
    insert into tablemain values (3, 1000, 7.44);
    insert into tablemain values (3, 1006, 447.88);
    create table tableoption (
      y_id number (20),
      x_id number (20),
      type_cd varchar2(20)
    insert into tableoption values (800, 1, 'Type1');
    insert into tableoption values (800, 3, 'Type2');
    insert into tableoption values (801, 1, 'Type2');
    insert into tableoption values (802, 2, 'Type1');
    create table tablesub (
      y_id number (20),
      z_id number (20)
    insert into tablesub values (800, 1000);
    insert into tablesub values (800, 1001);
    insert into tablesub values (800, 1004);
    insert into tablesub values (800, 1006);
    insert into tablesub values (801, 1001);
    insert into tablesub values (801, 1002);
    insert into tablesub values (801, 1005);
    insert into tablesub values (801, 1006);
    insert into tablesub values (802, 1005);
    insert into tablesub values (802, 1004);Query:
    SELECT Nvl(option1.y_id, option2.y_id) as y_id,
           Nvl(option1.x_id, option2.x_id) as x_id,
           mains.z_id,
           mains.amount
    FROM   tablemain mains
           left join (SELECT x_id,
                             y_id
                      FROM   tableoption
                      WHERE  type_cd = 'Type1') option1
             ON mains.x_id = option1.x_id
           left join (SELECT x_id,
                             y_id
                      FROM   tableoption
                      WHERE  type_cd = 'Type2') option2
             ON mains.x_id = option2.x_id
           left join tablesub sub
             ON mains.z_id = sub.z_id
                AND sub.y_id = Nvl(option1.y_id, option2.y_id)
    WHERE  sub.z_id IS NULL
           AND sub.y_id IS NULL What the output should be:
    y_id ---- x_id ---- z_id ---- amount
    800 ---- 1 ---- 1002 ---- 67.85
    800 ---- 1 ---- 1003 ---- 997.85
    801 ---- 1 ---- 1000 ---- 6767.45
    801 ---- 1 ---- 1003 ---- 997.85
    802 ---- 2 ---- 1002 ---- 1997.85
    Currently the output of the query is:
    800 ---- 1 ---- 1002 ---- 67.85
    800 ---- 1 ---- 1003 ---- 997.85
    802 ---- 2 ---- 1002 ---- 1997.85
    It is missing where 801 is type2 only in the tableoption:
    801 ---- 1 ---- 1000 ---- 6767.45
    801 ---- 1 ---- 1003 ---- 997.85
    Edited by: Hazy on Feb 22, 2012 3:25 PM

  • 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?

  • Ora-00904 left outer join

    Hi,
    I am trying to create a materialized view and trying replace + left outer join with 'left outer join' clause. I am getting
    ERROR at line 68:
    ORA-00904: "RF"."DATA_TYPE_ID": invalid identifier
    Here is the sql I am using. Any help is appreciated.
    CREATE MATERIALIZED VIEW HHC_CUSTOM.HHC_RESULT_FIELD_DIMENSION0925 (DATA_ELEMENT_ID,FIELD,PROFILE,PROFILE_ID,PARENT_FIELD,PARENT_PROFILE,PARENT_PROFILE_ID,DATA_TYPE,DECODE_TYPE,CFG_GROUP,CFG_SET,ACTIVITY_COUNT)
    TABLESPACE CUSTOM_01
    PCTUSED 0
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 80K
    NEXT 1M
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    PCTINCREASE 0
    BUFFER_POOL DEFAULT
    FLASH_CACHE DEFAULT
    CELL_FLASH_CACHE DEFAULT
    NOCACHE
    ENABLE ROW MOVEMENT
    NOLOGGING
    NOCOMPRESS
    NOPARALLEL
    BUILD IMMEDIATE
    REFRESH COMPLETE on DEMand
    WITH PRIMARY KEY
    AS
    /* Formatted on 9/25/2012 11:53:36 AM (QP5 v5.215.12089.38647) */
    SELECT /*+ ALL_ROWS FULL(rf) FULL(dt) FULL(dc) FULL(rd) FULL(mc) FULL(ad) FULL(ag) USE_HASH(rf,dt,dc,rd,mc,ad,ag) INDEX(prf,KP_RESULT_FIELD) INDEX(prd,KP_RESULT_PROFILE) INDEX(pmc,KP_RESULT_MULTI_FIELD_PROFILE) INDEX(pad,KP_ASSESS_PROFILE) INDEX(pag,KP_ASSESS_MULTI_FIELD_PROFILE) USE_NL(prf,prd,pmc,pad,pag) ORDERED(rf,dt,dc,rd,mc,ad,ag,prf,prd,pmc,pad,pag) */
    rf.data_element_id AS data_element_id,
    rf.name AS field,
    DECODE (SUBSTR (rf.data_element_id, 1, 3),
    'RD/', rd.name,
    'AG/', ag.name,
    'AD/', ad.name,
    'MC/', mc.name)
    AS profile,
    DECODE (SUBSTR (rf.data_element_id, 1, 3),
    'RD/', rd.profile_id,
    'AG/', ag.profile_id,
    'AD/', ad.profile_id,
    'MC/', mc.profile_id)
    AS profile_id,
    prf.name AS parent_field,
    DECODE (SUBSTR (rf.parent_profile_field_id, 1, 3),
    NULL, NULL,
    'RD/', prd.name,
    'AD/', pad.name,
    'AG/', pag.NAME, --shouldn't happen
    'MC/', pmc.name --shouldn't happen
    AS parent_profile,
    DECODE (SUBSTR (rf.parent_profile_field_id, 1, 3),
    NULL, NULL,
    'RD/', prd.profile_id,
    'AD/', pad.profile_id,
    'AG/', pag.profile_id, --shouldn't happen
    'MC/', pmc.profile_id --shouldn't happen
    AS parent_profile_id,
    dt.name AS data_type,
    NVL (dc.name,
    DECODE (UPPER (dt.name), 'ORGANISM', 'Organism', 'Not Coded'))
    AS decode_type,
    NVL (cfg.cfg_group, 'UNDEFINED') AS cfg_group,
    NVL (cfg.cfg_set, 'UNDEFINED') AS cfg_set,
    DECODE (rslt.data_element_id, NULL, 0, rslt.activity_count)
    AS activity_count
    FROM ud_master.result_field rf,ud_master.result_field prf
    join ud_master.data_type dt on (rf.data_type_id=dt.data_type_id)
    left outer join ud_master.decode_type dc on (rf.decode_source_id = dc.decode_source_id)
    left outer join ud_master.result_profile rd on (rf.profile_id = rd.profile_id)
    left outer join ud_master.result_multi_field_profile mc on (rf.profile_id = mc.profile_id)
    left outer join ud_master.assess_profile ad on (rf.profile_id = ad.profile_id)
    left outer join ud_master.assess_multi_field_profile ag on (rf.profile_id = ag.profile_id)
    left outer join ud_master.result_field rf on (prf.parent_profile_field_id = rf.data_element_id)
    left outer join ud_master.result_profile prd on (prf.profile_id = prd.profile_id)
    left outer join ud_master.result_multi_field_profile pmc on (prf.profile_id = pmc.profile_id)
    left outer join ud_master.assess_profile pad on (prf.profile_id = pad.profile_id)
    left outer join ud_master.assess_multi_field_profile pag on (rf.profile_id = pag.profile_id)
    left outer join (SELECT * FROM hhc_custom.dw_cfg_v WHERE cfg_type_id = 1) cfg on (rf.data_element_id = cfg.cfg_value)
    left outer join (SELECT data_element_id, COUNT (*) AS activity_count FROM ud_master.result GROUP BY data_element_id) rslt on (rf.data_element_id = rslt.data_element_id);
    Regards,
    Kotesh

    Hi Monica,
    I need to have 2 aliases for ud_master.result_field table
    So I f I change it like this
    CREATE MATERIALIZED VIEW HHC_CUSTOM.HHC_RESULT_FIELD_DIMENSION0925 (DATA_ELEMENT_ID,FIELD,PROFILE,PROFILE_ID,PARENT_FIELD,PARENT_PROFILE,PARENT_PROFILE_ID,DATA_TYPE,DECODE_TYPE,CFG_GROUP,CFG_SET,ACTIVITY_COUNT)
    TABLESPACE CUSTOM_01
    PCTUSED 0
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 80K
    NEXT 1M
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    PCTINCREASE 0
    BUFFER_POOL DEFAULT
    FLASH_CACHE DEFAULT
    CELL_FLASH_CACHE DEFAULT
    NOCACHE
    ENABLE ROW MOVEMENT
    NOLOGGING
    NOCOMPRESS
    NOPARALLEL
    BUILD IMMEDIATE
    REFRESH COMPLETE on DEMand
    WITH PRIMARY KEY
    AS
    /* Formatted on 9/25/2012 11:53:36 AM (QP5 v5.215.12089.38647) */
    SELECT /*+ ALL_ROWS FULL(rf) FULL(dt) FULL(dc) FULL(rd) FULL(mc) FULL(ad) FULL(ag) USE_HASH(rf,dt,dc,rd,mc,ad,ag) INDEX(prf,KP_RESULT_FIELD) INDEX(prd,KP_RESULT_PROFILE) INDEX(pmc,KP_RESULT_MULTI_FIELD_PROFILE) INDEX(pad,KP_ASSESS_PROFILE) INDEX(pag,KP_ASSESS_MULTI_FIELD_PROFILE) USE_NL(prf,prd,pmc,pad,pag) ORDERED(rf,dt,dc,rd,mc,ad,ag,prf,prd,pmc,pad,pag) */
    rf.data_element_id AS data_element_id,
    rf.name AS field,
    DECODE (SUBSTR (rf.data_element_id, 1, 3),
    'RD/', rd.name,
    'AG/', ag.name,
    'AD/', ad.name,
    'MC/', mc.name)
    AS profile,
    DECODE (SUBSTR (rf.data_element_id, 1, 3),
    'RD/', rd.profile_id,
    'AG/', ag.profile_id,
    'AD/', ad.profile_id,
    'MC/', mc.profile_id)
    AS profile_id,
    prf.name AS parent_field,
    DECODE (SUBSTR (rf.parent_profile_field_id, 1, 3),
    NULL, NULL,
    'RD/', prd.name,
    'AD/', pad.name,
    'AG/', pag.NAME, --shouldn't happen
    'MC/', pmc.name --shouldn't happen
    AS parent_profile,
    DECODE (SUBSTR (rf.parent_profile_field_id, 1, 3),
    NULL, NULL,
    'RD/', prd.profile_id,
    'AD/', pad.profile_id,
    'AG/', pag.profile_id, --shouldn't happen
    'MC/', pmc.profile_id --shouldn't happen
    AS parent_profile_id,
    dt.name AS data_type,
    NVL (dc.name,
    DECODE (UPPER (dt.name), 'ORGANISM', 'Organism', 'Not Coded'))
    AS decode_type,
    NVL (cfg.cfg_group, 'UNDEFINED') AS cfg_group,
    NVL (cfg.cfg_set, 'UNDEFINED') AS cfg_set,
    DECODE (rslt.data_element_id, NULL, 0, rslt.activity_count)
    AS activity_count
    FROM ud_master.result_field rf,ud_master.result_field prf
    join ud_master.data_type dt on (prf.data_type_id=dt.data_type_id)
    left outer join ud_master.decode_type dc on (prf.decode_source_id = dc.decode_source_id)
    left outer join ud_master.result_profile rd on (prf.profile_id = rd.profile_id)
    left outer join ud_master.result_multi_field_profile mc on (prf.profile_id = mc.profile_id)
    left outer join ud_master.assess_profile ad on (prf.profile_id = ad.profile_id)
    left outer join ud_master.assess_multi_field_profile ag on (prf.profile_id = ag.profile_id)
    left outer join ud_master.result_field rf on (prf.parent_profile_field_id = rf.data_element_id)
    left outer join ud_master.result_profile prd on (prf.profile_id = prd.profile_id)
    left outer join ud_master.result_multi_field_profile pmc on (prf.profile_id = pmc.profile_id)
    left outer join ud_master.assess_profile pad on (prf.profile_id = pad.profile_id)
    left outer join ud_master.assess_multi_field_profile pag on (rf.profile_id = pag.profile_id)
    left outer join (SELECT * FROM hhc_custom.dw_cfg_v WHERE cfg_type_id = 1) cfg on (rf.data_element_id = cfg.cfg_value)
    left outer join (SELECT data_element_id, COUNT (*) AS activity_count FROM ud_master.result GROUP BY data_element_id) rslt on (rf.data_element_id = rslt.data_element_id);
    I am getting the following error
    DECODE (SUBSTR (rf.parent_profile_field_id, 1, 3),
    ERROR at line 51:
    ORA-00918: column ambiguously defined
    Following is the original query I tried to modify
    CREATE MATERIALIZED VIEW HHC_CUSTOM.HHC_RESULT_FIELD_DIMENSION (DATA_ELEMENT_ID,FIELD,PROFILE,PROFILE_ID,PARENT_FIELD,PARENT_PROFILE,PARENT_PROFILE_ID,DATA_TYPE,DECODE_TYPE,CFG_GROUP,CFG_SET,ACTIVITY_COUNT)
    TABLESPACE CUSTOM_01
    PCTUSED 0
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 80K
    NEXT 1M
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    PCTINCREASE 0
    BUFFER_POOL DEFAULT
    FLASH_CACHE DEFAULT
    CELL_FLASH_CACHE DEFAULT
    NOCACHE
    ENABLE ROW MOVEMENT
    NOLOGGING
    NOCOMPRESS
    NOPARALLEL
    BUILD IMMEDIATE
    REFRESH COMPLETE ON DEMAND
    WITH PRIMARY KEY
    AS
    /* Formatted on 9/26/2012 1:59:27 PM (QP5 v5.215.12089.38647) */
    SELECT /*+ ALL_ROWS FULL(rf) FULL(dt) FULL(dc) FULL(rd) FULL(mc) FULL(ad) FULL(ag) USE_HASH(rf,dt,dc,rd,mc,ad,ag) INDEX(prf,KP_RESULT_FIELD) INDEX(prd,KP_RESULT_PROFILE) INDEX(pmc,KP_RESULT_MULTI_FIELD_PROFILE) INDEX(pad,KP_ASSESS_PROFILE) INDEX(pag,KP_ASSESS_MULTI_FIELD_PROFILE) USE_NL(prf,prd,pmc,pad,pag) ORDERED(rf,dt,dc,rd,mc,ad,ag,prf,prd,pmc,pad,pag) */
    rf.data_element_id AS data_element_id,
    rf.name AS field,
    DECODE (SUBSTR (rf.data_element_id, 1, 3),
    'RD/', rd.name,
    'AG/', ag.name,
    'AD/', ad.name,
    'MC/', mc.name)
    AS profile,
    DECODE (SUBSTR (rf.data_element_id, 1, 3),
    'RD/', rd.profile_id,
    'AG/', ag.profile_id,
    'AD/', ad.profile_id,
    'MC/', mc.profile_id)
    AS profile_id,
    prf.name AS parent_field,
    DECODE (SUBSTR (rf.parent_profile_field_id, 1, 3),
    NULL, NULL,
    'RD/', prd.name,
    'AD/', pad.name,
    'AG/', pag.NAME, --shouldn't happen
    'MC/', pmc.name --shouldn't happen
    AS parent_profile,
    DECODE (SUBSTR (rf.parent_profile_field_id, 1, 3),
    NULL, NULL,
    'RD/', prd.profile_id,
    'AD/', pad.profile_id,
    'AG/', pag.profile_id, --shouldn't happen
    'MC/', pmc.profile_id --shouldn't happen
    AS parent_profile_id,
    dt.name AS data_type,
    NVL (dc.name,
    DECODE (UPPER (dt.name), 'ORGANISM', 'Organism', 'Not Coded'))
    AS decode_type,
    NVL (cfg.cfg_group, 'UNDEFINED') AS cfg_group,
    NVL (cfg.cfg_set, 'UNDEFINED') AS cfg_set,
    DECODE (rslt.data_element_id, NULL, 0, rslt.activity_count)
    AS activity_count
    FROM ud_master.result_field rf,
    ud_master.data_type dt,
    ud_master.decode_type dc,
    ud_master.result_profile rd,
    ud_master.result_multi_field_profile mc,
    ud_master.assess_profile ad,
    ud_master.assess_multi_field_profile ag,
    ud_master.result_field prf,
    ud_master.result_profile prd,
    ud_master.result_multi_field_profile pmc,
    ud_master.assess_profile pad,
    ud_master.assess_multi_field_profile pag,
    (SELECT *
    FROM hhc_custom.dw_cfg_v
    WHERE cfg_type_id = 1) cfg,
    ( SELECT data_element_id, COUNT (*) AS activity_count
    FROM ud_master.result
    GROUP BY data_element_id) rslt
    WHERE rf.data_type_id = dt.data_type_id
    AND rf.decode_source_id = dc.decode_source_id(+)
    AND rf.profile_id = rd.profile_id(+)
    AND rf.profile_id = mc.profile_id(+)
    AND rf.profile_id = ad.profile_id(+)
    AND rf.profile_id = ag.profile_id(+)
    AND rf.parent_profile_field_id = prf.data_element_id(+)
    AND prf.profile_id = prd.profile_id(+)
    AND prf.profile_id = pmc.profile_id(+)
    AND prf.profile_id = pad.profile_id(+)
    AND prf.profile_id = pag.profile_id(+)
    AND rf.data_element_id = cfg.cfg_value(+)
    AND rf.data_element_id = rslt.data_element_id(+);
    Can you tell me how can I rewrite it with 'LEFT OUTER JOIN' syntax?
    Regards,
    Kotesh

  • 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

  • Left outer join query

    Hi Experts,
        I am facing a problem with left outer join query. Am using one standard table and ztable for this join. My problem is values are not extracted from the Ztable.
    Query:
          SELECT  b~lifnr b~belnr b~gjahr b~xblnr b~shkzg b~blart b~zfbdt b~budat b~wrbtr
             b~wskto b~zlspr s~EXTRACT_STATUS s~maturity_date FROM bsik AS b
             LEFT OUTER JOIN zprm_rvne_sapdoc AS s
             ON s~belnr  EQ  b~belnr
             AND s~gjahr EQ b~gjahr
             INTO CORRESPONDING FIELDS OF TABLE it_join
                WHERE b~zlsch = p_zlsch
                AND b~xblnr IN so_invno
                ORDER BY b~lifnr b~xblnr.
    I have all entries of BSIK table in Ztable with extract status as Y but this query is not fetching extract status and maturity date of ztable so it is blank in the internal table.
    Need solution.
    Regards
    Sridevi S

    Hi,
    see the sample wiki for writing the Left outer join
    http://wiki.sdn.sap.com/wiki/display/Snippets/EmployeeInfotype0000to9999ChangeHistory
    Specifying Two or More Database Tables as a Left Outer Join
    The left outer join, on the other hand, reads lines from the left-hand database table or join even if there is no corresponding line in the right-hand table.
    SELECT...
      FROM <tab> LEFT [OUTER] JOIN <dbtab> [AS <alias>] ON <cond>
           <options>
    <tab> and <dbtab> are subject to the same rules and conditions as in an inner join. The OUTER addition is optional. The tables are linked in the same way as the inner join with the one exception that all lines selected from <tab> are included in the final selection. If <dbtab> does not contain any lines that meet the condition <cond>, the system includes a single line in the selection whose columns from <dbtab> are filled with null values.
    In the left outer join, more restrictions apply to the condition <cond> than in the inner join. In addition to the above restrictions:
    EQ or = is the only permitted relational operator.
    There must be at least one comparison between columns from <tab> and <dbtab>.
    The WHERE clause may not contain any comparisons with columns from <dbtab>. All comparisons using columns from <dbtab> must appear in the condition <cond>.
    If we have two tables named stud1,stud2 with the following data
    Stud1: id Name stud2: id Name
    1 xxx 1 aaa
    2 yyy 2 bbb
    3 zzz 4 ccc
    4 www 6 ddd
    When we use Left Outer Join we get the output as:
    1 aaa
    2 bbb
    3 <Null>
    4 ccc
    When we use Right Outer Join we get the output as:
    1 aaa
    2 bbb
    4 ccc
    <Null> ddd
    When we use Full Outer Join we get the output as:
    1 aaa
    2 bbb
    3 <Null>
    4 ccc
    <Null> ddd
    Prabhudas

  • 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

  • LEFT OUTER JOIN SQL syntax

    Haven't seen a solution to this on the forum or in the docs. My last post timed out with no responses, but I still don't know if I have a possible solution.
    I've got 2 objects, Task and Role, that are linked in a M-M relationship.
    My tables are:
    T_TASKS
    T_TASKSROLES
    T_ROLES
    I am querying T_TASKS and joining on T_TASKSROLES and T_ROLES, but I need to use an outer join because not all Tasks have a Role in T_TASKSROLES.
    In SQL Server, my FROM clause SHOULD look like this:
    FROM (T_TASKSROLES t2 LEFT OUTER JOIN T_TASKS t1 ON t1.ID = t2.TASKID) LEFT OUTER JOIN T_ROLES t0 ON t0.ID = t2.ROLEID
    however, if I use eb.anyOfAllowingNone(_roles) in my ExpressionBuilder. TopLink creates a LEFT OUTER JOIN clause that looks like this:
    FROM T_ROLES t0 LEFT OUTER JOIN T_TASKS t1 ON((t0.ID = T_TASKSROLES.ROLEID) AND (t1.ID = T_TASKSROLES.TASKID))
    I can see the logic in how it builds this clause. But, it doesn't parse in SQL Server.
    Is there a way to effect how TopLink generates the FROM clause for outer joins? I mean, I understand how to use the XXXPlatform.java source files and can change whether to use OuterJoin in the WHERE clause or not. But, I can't see anything in the platform class that would allow me to figure this out.
    I realize I could write SQL manually, but is there a way to do this so that the same code would work on SQL Server, Oracle, and Sybase (assuming the DatabaseLogin is configured appropriately)?
    It just seems like LEFT OUTER JOIN when joining M-M relationships isn't generating proper SQL. Is the TopLink SQL SQL92-compliant?
    I should add that I have tried to change SQLServerPlatform to have shouldPrintOuterJoinInWhereClause() return "true". This embeds a "=*" in the join conditions in the WHERE clause.
    SQL Server 2000 still supports this syntax, but the "=*" isn't ALWAYS the correct operator. It is important to put the "*" on the correct side of the expression. TopLink always prints "=*", but the operators are not always in the correct order. So, it tries to create a "left join" on the wrong table.
    So my other question, is it possible to force TopLink to remember to put the outer join table in the RIGHT SIDE?
    Nate

    The workaround is actually more complicated than that, and it can't be fixed by changing only the operator.
    In the queries you listed, the only difference is which side of the "AND" the expressions appear on.
    Change "(t2.rightid (+)= t1.rightid)" to "(t1.rightid (+)= t2.rightid)" and I'm guessing (although not sure because I am testing with SQL Server at the moment), that you'll get a similar query error as I did.
    The bug here is that the default M-M selection criteria creates "reltable = table1 AND table2 = reltable". There is no operator that can satisfy this expression.
    So, the fix that I made, for all of my M-M Mappings was to set the SelectionCriteria manually using the following Expression (returned from this method):
    // This puts M-M relationship tables on the same side of expressions so that OUTER JOINS can be supported.
    private Expression getSameSideExpression() {
              // target side
              Expression selectionCriteria = null;
    Enumeration e2 = getTargetKeyFields().elements();
    Enumeration e = getTargetRelationKeyFields().elements();
    ExpressionBuilder eb = new ExpressionBuilder();
    Expression relTableExp = null;
    while(e2.hasMoreElements()) {
    DatabaseField df = (DatabaseField) e.nextElement();
    DatabaseField df2 = (DatabaseField) e2.nextElement();
    if(relTableExp == null){
    relTableExp = eb.getTable(df.getTable());
    Expression targetFieldExp = eb.getField(df2);
    Expression relFieldExp = relTableExp.getField(df);
    Expression joinExp = relFieldExp.equal(targetFieldExp);
    if(selectionCriteria == null)
    selectionCriteria = joinExp;
    else
    selectionCriteria = joinExp.and(selectionCriteria);
              // source side
    e = getSourceRelationKeyFields().elements();
              e2 = getSourceKeyFields().elements();
    while(e.hasMoreElements()) {
    DatabaseField df = (DatabaseField) e.nextElement();
    DatabaseField df2 = (DatabaseField) e2.nextElement();
    Expression relFieldExp = relTableExp.getField(df);
    Expression sourceFieldExp = eb.getParameter(df2);
    Expression joinExp = relFieldExp.equal(sourceFieldExp);
    if(selectionCriteria == null)
                        selectionCriteria = joinExp;
    else
    selectionCriteria = joinExp.and(selectionCriteria);
              return selectionCriteria;
    This changes the M-M Selection Criteria to "table1 = reltable AND table2 = reltable". Now that this is consistent, using the WHERE clause for my joins in SQL Server is possible.
    If you can think of any other problems this change may have, please let me know.
    Thanks for the help.
    Nate

  • SQL Server "LEFT OUTER JOIN" syntax

    Haven't seen a solution to this on the forum or in the docs.
    I've got 2 objects, Task and Role, that are linked in a M-M relationship.
    My tables are:
    T_TASKS
    T_TASKSROLES
    T_ROLES
    I am querying T_TASKS and joining on T_ROLES, but I need to use an outer join on T_ROLES.
    In SQL Server, my FROM clause SHOULD look like this:
    FROM (T_TASKSROLES t2 LEFT OUTER JOIN T_TASKS t1 ON t1.ID = t2.TASKID) LEFT OUTER JOIN T_ROLES t0 ON t0.ID = t2.ROLEID
    however, if I use eb.anyOfAllowingNone(_roles) in my ExpressionBuilder. TopLink creates a LEFT OUTER JOIN clause that looks like this:
    FROM T_ROLES t0 LEFT OUTER JOIN T_TASKS t1 ON ((t0.ID = T_TASKSROLES.ROLEID) AND (t1.ID = T_TASKSROLES.TASKID))
    I can see the logic in how it builds this clause. But, it doesn't parse in SQL Server.
    Is there a way to effect how TopLink generates the FROM clause for outer joins? I mean, I understand how to use the XXXPlatform.java source files and can change whether to use OuterJoin in the WHERE clause or not. But, I can't see anything in the platform class that would allow me to figure this out.
    I realize I could write SQL manually, but is there a way to do this so that the same code would work on SQL Server, Oracle, and Sybase (assuming the DatabaseLogin is configured appropriately)?
    It just seems like LEFT OUTER JOIN when joining M-M relationships isn't generating proper SQL. Is the TopLink SQL SQL92-compliant?
    Nate

    I should add that I have tried to change SQLServerPlatform to have shouldPrintOuterJoinInWhereClause() return "true". This embeds a "=*" in the join conditions in the WHERE clause.
    SQL Server 2000 still supports this syntax, but the "=*" isn't ALWAYS the correct operator. It is IMPORTANT to put the "*" on the correct side of the expression.
    TopLink always prints "=*", and it always puts it in the correct space, but the OPERATORS are not always in the correct order so you are creating a "left join" on the wrong table.
    So my other question, is it possible to FORCE TopLink to remember to put the outer join table in the RIGHT SIDE?
    Nate

Maybe you are looking for

  • HT3777 How to install Boot Camp on 32bit Windows 8 on a 2011 MacBook Pro?

    I used Boot Camp to install Windows 8 Consumer Preview as the 2nd OS on my 2011 MacBook Pro. However after the installation I cannot install the additional Boot Camp just the drivers for webcam/wifi/ethernet/cardreader/display/chipset etc. But I woul

  • Problem in Query Transportation

    Dear All, We are transporting the query from 3.0B to BI 7. The BI 7 analyser is working fine with all the variables but in the fiscal year period it is giving the error. When we remove it from the query designer BI 7 and including the optional variab

  • Convert quicktime to avi or mpeg 2

    I have made a short movie with FCE. The client wants it on disc in either AVI or MPEG 1 or 2. Have tried exporting to quicktime and then saving as AVI, but it saves as .mov What am I doing wrong? Any help much appreciated

  • What shall I do with these datasources

    I'm working on infocube 0pp_c03 and the datasources which go with it are 0pp_wccp, 2lis_04_s281, and 2lis_04_p_arbpl and I'm not able to find them in rsa6, and I therefore can't find them in rsa5.  So what shall I do inorder for me to install them in

  • Displaying Hierarchies in columns (i.e. across not drill down)

    Hi Guys, My client needs me to display the Organisational Hierarchy and its attribute (manager of each org unit) in columns. i.e. org unit level1, org unit level1 manager, org unit level2, org unit level2 manager, org unit level3, org unit level3 man