Outer join combination fails in following query

Hi All,
Join on table fails in following scenario,
--Employee table  
CREATE TABLE "EMP"
   ("EMP_ID" NUMBER(10,0) NOT NULL ENABLE,
     "FNAME" NVARCHAR2(50) NOT NULL ENABLE,
     "LNAME" NVARCHAR2(50) NOT NULL ENABLE
--Mapping between Task type & Department
   CREATE TABLE "TASKTYPE_FOR_DEPT"
   (     "TASKTYPE_FOR_DEPT_ID" NUMBER(10,0) NOT NULL ENABLE,
     "DEPT_ID" NUMBER(10,0) NOT NULL ENABLE,
     "TASK_TYPE_CD" NVARCHAR2(10) NOT NULL ENABLE
-- Departmentwise employee hierarchy  
CREATE TABLE "EMP_HIERARCHY"
   (     "EMP_ID" NUMBER(10,0) NOT NULL ENABLE,
     "DEPT_ID" NUMBER(10,0) NOT NULL ENABLE
   -- Tasks Details
CREATE TABLE "TASKS"
   (     "TASK_ID" NUMBER(10,0) NOT NULL ENABLE,
     "TASK_PRIORITY" NVARCHAR2(10) NOT NULL ENABLE,
     "TASK_TYPE" VARCHAR2(20 BYTE)
   -- Tasks allocation
CREATE TABLE "TASKSALLOCATION"
   (     "TASKALLOCATION_ID" NUMBER(10,0) NOT NULL ENABLE,
     "EMP_ID" NUMBER(10,0) NOT NULL ENABLE,
     "TASK_ID" NUMBER(10,0) NOT NULL ENABLE
Insert into EMP (EMP_ID,FNAME,LNAME) values (1,'XYZ','DFD');
Insert into EMP (EMP_ID,FNAME,LNAME) values (2,'DFDS','FD');
Insert into EMP (EMP_ID,FNAME,LNAME) values (3,'FDSF','GFH');
Insert into EMP (EMP_ID,FNAME,LNAME) values (6,'GFHGF','GFHS');
Insert into EMP (EMP_ID,FNAME,LNAME) values (4,'GFD','FDG');
Insert into EMP (EMP_ID,FNAME,LNAME) values (5,'DSFDS','FDSAF');
Insert into EMP (EMP_ID,FNAME,LNAME) values (7,'GHGY','EWE');
Insert into EMP (EMP_ID,FNAME,LNAME) values (8,'FGRFSAD','SADF');
Insert into TASKTYPE_FOR_DEPT (TASKTYPE_FOR_DEPT_ID,DEPT_ID,TASK_TYPE_CD) values (1,1,'T1');
Insert into EMP_HIERARCHY (EMP_ID,DEPT_ID) values (1,1);
Insert into EMP_HIERARCHY (EMP_ID,DEPT_ID) values (2,1);
Insert into EMP_HIERARCHY (EMP_ID,DEPT_ID) values (3,1);
Insert into EMP_HIERARCHY (EMP_ID,DEPT_ID) values (4,1);
Insert into EMP_HIERARCHY (EMP_ID,DEPT_ID) values (5,1);
Insert into EMP_HIERARCHY (EMP_ID,DEPT_ID) values (6,1);
Insert into EMP_HIERARCHY (EMP_ID,DEPT_ID) values (7,1);
Insert into EMP_HIERARCHY (EMP_ID,DEPT_ID) values (8,1);
Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (1,'HIGH','T1');
Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (2,'MEDIUM','T1');
Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (3,'LOW','T1');
Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (4,'HIGH','T1');
Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (5,'MEDIUM','T1');
Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (6,'LOW','T1');
Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (7,'HIGH','T1');
Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (8,'MEDIUM','T1');
Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (9,'LOW','T1');
Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (10,'HIGH','T1');
Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (11,'MEDIUM','T1');
Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (12,'LOW','T1');
Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (13,'HIGH','T1');
Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (14,'MEDIUM','T1');
Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (15,'LOW','T1');
Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (16,'HIGH','T1');
Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (17,'MEDIUM','T1');
Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (18,'LOW','T1');
Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (19,'HIGH','T1');
Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (20,'MEDIUM','T1');
Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (21,'LOW','T1');
Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (22,'HIGH','T1');
Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (23,'MEDIUM','T1');
Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (24,'LOW','T1');
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (1,1,1);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (2,2,1);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (3,3,2);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (4,3,3);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (5,4,4);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (6,4,5);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (7,4,6);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (8,4,7);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (9,5,6);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (10,6,8);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (12,8,8);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (13,8,10);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (14,8,11);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (15,8,12);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (16,6,13);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (17,5,14);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (18,3,12);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (19,3,13);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (20,2,15);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (21,1,16);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (22,2,17);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (23,1,18);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (24,4,19);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (25,6,20);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (26,5,21);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (27,1,22);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (28,3,23);
COMMIT;We want all resources belongs to department for a given case type with assinged tasks count & grouping with priority.
I tried the following query,
select emp.fname || ' ' || emp.lname EMP_NAME
     , sum(DECODE(tasks.TASK_PRIORITY, 'HIGH', 1, 0)) HIGH
     , sum(DECODE(tasks.TASK_PRIORITY, 'MEDIUM', 1, 0)) MEDIUM
     , sum(DECODE(tasks.TASK_PRIORITY, 'LOW', 1, 0)) LOW
  from emp,
  EMP_HIERARCHY,
  TASKSALLOCATION,
  TASKS,
  TASKTYPE_FOR_DEPT 
  where
   TASKTYPE_FOR_DEPT.TASK_TYPE_CD = 'T1'
   emp.EMP_ID = TASKSALLOCATION.EMP_ID(+)
  and TASKSALLOCATION.TASK_ID = tasks.TASK_ID(+)
  and tasks.TASK_TYPE = TASKTYPE_FOR_DEPT.TASK_TYPE_CD
  and TASKTYPE_FOR_DEPT.dept_id = EMP_HIERARCHY.dept_id
-- and EMP_HIERARCHY.emp_id = emp.EMP_ID
group by emp.fname || ' ' || emp.lname;
It is not working properly.
Actually we are also looking the employee for whom task has been not allocated but belong to same department.
In above resultset employee 'GHGY EWE' belongs to same department but no taks is allocated.
We are expecting resultset something like this.
with
    t as
          select     'GFHGF GFHS' as emp_name, 1 as highPriority,     2 as mediumPriority, 0 as lowPriority FROM dual union all
          select     'FDSF GFH',               1     ,     2     ,     2     FROM dual union all
          select     'XYZ DFD'     ,          3     ,     0     ,     1     FROM dual union all
          select     'GHGY EWE',          0     ,     0     ,     0     FROM dual union all
          select     'DFDS FD',               1     ,     1     ,     1     FROM dual union all
          select     'GFD FDG',               3     ,     1     ,     1     FROM dual union all
          select     'FGRFSAD SADF',          1     ,     2     ,     1     FROM dual union all
          select     'DSFDS FDSAF',          0     ,     1     ,     2     FROM dual
          );Note : We are using Oracle 11.2.0.2.0 version

I do not know your design, so you will have to change left join with plain join where appropriate. Otherwise:
select  emp1.fname || ' ' || emp1.lname EMP_NAME,
        sum(DECODE(tasks.TASK_PRIORITY, 'HIGH', 1, 0)) HIGH,
        sum(DECODE(tasks.TASK_PRIORITY, 'MEDIUM', 1, 0)) MEDIUM,
        sum(DECODE(tasks.TASK_PRIORITY, 'LOW', 1, 0)) LOW
  from      emp1
        left join
            EMP_HIERARCHY
          on EMP_HIERARCHY.emp_id = emp1.EMP_ID
        left join
            TASKTYPE_FOR_DEPT
          on (
                  TASKTYPE_FOR_DEPT.TASK_TYPE_CD = 'T1'
              and
                  TASKTYPE_FOR_DEPT.dept_id = EMP_HIERARCHY.dept_id
        left join
            TASKSALLOCATION
          on emp1.EMP_ID = TASKSALLOCATION.EMP_ID
        left join
            TASKS
          on (
                  tasks.TASK_TYPE = TASKTYPE_FOR_DEPT.TASK_TYPE_CD
              and
                  tasks.TASK_ID = TASKSALLOCATION.TASK_ID
  group by emp1.fname || ' ' || emp1.lname
EMP_NAME                   HIGH     MEDIUM        LOW
FGRFSAD SADF                  1          2          1
XYZ DFD                       3          0          1
GHGY EWE                      0          0          0
GFHGF GFHS                    1          2          0
GFD FDG                       3          1          1
DFDS FD                       1          1          1
FDSF GFH                      1          2          2
DSFDS FDSAF                   0          1          2
8 rows selected.
SQL> SY.

Similar Messages

  • How to use outer join condition in my below query.

    Hi All,
    How to use outer join condition in my below query.
    In the table  APPS_JP.GEDIS_OFFER_HEADER goh I have more records
    in the table APPS_JP.GEDIS_ORDER_BUILDS gob I have less number of records.
    I want all the records from APPS_JP.GEDIS_OFFER_HEADER goh
    including other conditions.
    I have tried goh.OFFER_NO=gob.OFFER_NO(+) but same result.
    [code]SELECT   GOH.ORIG_SYSTEM,
               gsp.USER_NAME,
               goh.ORDER_NO,
               goh.OMEGA_ORDER_NUMBER,
               goh.ORDER_TYPE,
               gc.CUSTOMER_ID,
               gc.OMEGA_CUSTOMER_NUMBER,
               CASE WHEN gc.PRIVATE = 'N' THEN gc.CUSTOMER_NAME ELSE '' END
                  AS COMPANY_NAME,
               goh.ORDER_STATUS,
               goh.TOTAL_SELLING_PRICE,
               goh.TOTAL_MARGIN,
                  ga1.ADDRESS1
               || ','
               || ga1.ADDRESS2
               || ','
               || ga1.ADDRESS3
               || ','
               || ga1.POSTAL_CODE
               || ','
               || ga1.CITY
                  AS SHIPPING_ADDRESS,
                  ga2.ADDRESS1
               || ','
               || ga2.ADDRESS2
               || ','
               || ga2.ADDRESS3
               || ','
               || ga2.POSTAL_CODE
               || ','
               || ga2.CITY
                  AS BILLING_ADDRESS,
               ga.ADDRESS_ID,
               gol.DESCRIPTION,
               APPS_JP.TZ.to_local_date (goh.OFFER_DATE, goh.OFFER_DATE_UTC)
                  AS OFFER_DATE,
               gc.LEVEL_8,
               goh.NO_OF_BUILDS,
               gob.SFDC_ID,
               goh.PURCHASE_ORDER_NO AS PO,
               gc1.CUSTOMER_NAME AS END_USAGE,
               gol.LOB,
               goh.TOTAL_MARGIN_PCT,
               goh.TOTAL_DISCOUNT,
               goh.TOTAL_DISCOUNT_PCT
        FROM   APPS_JP.GEDIS_OFFER_HEADER goh,
               APPS_JP.GEDIS_ORDER_BUILDS gob,
               APPS_JP.GEDIS_ORDER_LINES gol,
               APPS_JP.GEDIS_OFFER_RELATED_CUSTOMER gorc,
               APPS_JP.GEDIS_OFFER_RELATED_CUSTOMER ship,
               APPS_JP.GEDIS_OFFER_RELATED_CUSTOMER bill,
               APPS_JP.GEDIS_CUSTOMER gc,
               APPS_JP.GEDIS_CUSTOMER gc1,
               APPS_JP.GEDIS_CONTACT gct,
               APPS_JP.GEDIS_ADDRESS ga,
               APPS_JP.GEDIS_ADDRESS_NORM ga1,
               APPS_JP.GEDIS_ADDRESS_NORM ga2,
               (SELECT   DISTINCT SALESPERSON_ID, USER_NAME
                  FROM   APPS_JP.GEDIS_SALESPERSON
                 WHERE   SALESPERSON_ID IN
                               (SELECT   TO_NUMBER (COLUMN_VALUE) AS SALESPERSON_ID
                                  FROM   TABLE (APPS_GLOBAL.SplitString ('337309'))))
               gsp
       WHERE       goh.ORDER_NO <> 0
               AND goh.OFFER_NO <> 0
               AND goh.OFFER_NO=gol.OFFER_NO
               AND gol.BUILD_NO = 1
               AND gol.LINE_NO = 1
               AND goh.OFFER_NO=gob.OFFER_NO
               AND gob.BUILD_NO = 1
               AND goh.OFFER_NO = gorc.OFFER_NO
               AND gct.CONTACT_ID = gorc.CONTACT_ID
               AND ga.CUSTOMER_ID = gc.CUSTOMER_ID
               AND ga.PRIMARY = 'Y'
               AND goh.LEAD_SALESPERSON=gsp.SALESPERSON_ID
               AND goh.OFFER_NO = ship.OFFER_NO
               AND ship.RELATION_TYPE = 'SHIP'
               AND ga1.ADDRESS_ID = ship.ADDRESS_ID
               AND ga1.CUSTOMER_ID = gc1.CUSTOMER_ID
               AND goh.OFFER_NO = bill.OFFER_NO
               AND bill.RELATION_TYPE = 'BILL'
               AND ga2.ADDRESS_ID = bill.ADDRESS_ID
               AND goh.OFFER_DATE BETWEEN APPS_JP.TZ.LOCAL_TO_DB_DATE (
                                             SYSDATE - 30
                                      AND  APPS_JP.TZ.LOCAL_TO_DB_DATE (SYSDATE)
               AND gorc.RELATION_TYPE = 'BASE'
               AND gorc.CUSTOMER_ID = gc.CUSTOMER_ID
               AND goh.SALES_CHANNEL = gc.SALES_CHANNEL
               AND gc.SALES_CHANNEL = 'SMB'
               AND goh.LEAD_SALESPERSON IN (goh.CREATED_BY, goh.LEAD_SALESPERSON)
    ORDER BY   goh.OFFER_NO;[/code]
    Please help me how to use this outer join condition.
    Thanks in advance.

    Hi,
    If you want all the rows from goh, then you don't want any conditions like  goh.OFFER_NO <> 0.
    Make all the joins to goh outer joins, and make all conditions that apply to any tables joined to goh (or to tables joined to them) part of the join condition, like this:
    FROM             APPS_JP.GEDIS_OFFER_HEADER     goh
    LEFT OUTER JOIN  APPS_JP.GEDIS_ORDER_BUILDS     gob  ON   gob.OFFER_NO = goh.OFFER_NO
                                                         AND  gob.BUILD_NO = 1
    LEFT OUTER JOIN  APPS_JP.GEDIS_ORDER_LINES      gol  ON   gol.OFFER_NO = goh.OFFER_NO
                                                         AND  gol.BUILD_NO = 1
                                                         AND  gol.LINE_NO  = 1
    LEFT OUTER JOIN  APPS_JP.GEDIS_OFFER_RELATED_CUSTOMER
                                                    gorc ...
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
    Simplify the problem as much as possible.  For example, do you really need all those tables to show what the problem is?  Of course, you need them in tyour real query, but if you understand a solution that only involves 4 or 5 tables, you'll know how to apply it to any number of tables.
    Explain, using specific examples, how you get those results from that data.Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
    See the forum FAQ https://forums.oracle.com/message/9362002#9362002

  • [8i] Need help with full outer join combined with a cross-join....

    I can't figure out how to combine a full outer join with another type of join ... is this possible?
    Here's some create table and insert statements for some basic sample data:
    CREATE TABLE     my_tab1
    (     record_id     NUMBER     NOT NULL     
    ,     workstation     VARCHAR2(4)
    ,     my_value     NUMBER
         CONSTRAINT my_tab1_pk PRIMARY KEY (record_id)
    INSERT INTO     my_tab1
    VALUES(1,'ABCD',10);
    INSERT INTO     my_tab1
    VALUES(2,'ABCD',15);
    INSERT INTO     my_tab1
    VALUES(3,'ABCD',5);
    INSERT INTO     my_tab1
    VALUES(4,'A123',5);
    INSERT INTO     my_tab1
    VALUES(5,'A123',10);
    INSERT INTO     my_tab1
    VALUES(6,'A123',20);
    INSERT INTO     my_tab1
    VALUES(7,'????',5);
    CREATE TABLE     my_tab2
    (     workstation     VARCHAR2(4)
    ,     wkstn_name     VARCHAR2(20)
         CONSTRAINT my_tab2_pk PRIMARY KEY (workstation)
    INSERT INTO     my_tab2
    VALUES('ABCD','WKSTN 1');
    INSERT INTO     my_tab2
    VALUES('A123','WKSTN 2');
    INSERT INTO     my_tab2
    VALUES('B456','WKSTN 3');
    CREATE TABLE     my_tab3
    (     my_nbr1     NUMBER
    ,     my_nbr2     NUMBER
    INSERT INTO     my_tab3
    VALUES(1,2);
    INSERT INTO     my_tab3
    VALUES(2,3);
    INSERT INTO     my_tab3
    VALUES(3,4);And, the results I want to get:
    workstation     sum(my_value)     wkstn_name     my_nbr1     my_nbr2
    ABCD          30          WKSTN 1          1     2
    ABCD          30          WKSTN 1          2     3
    ABCD          30          WKSTN 1          3     4
    A123          35          WKSTN 2          1     2
    A123          35          WKSTN 2          2     3
    A123          35          WKSTN 2          3     4
    B456          0          WKSTN 3          1     2
    B456          0          WKSTN 3          2     3
    B456          0          WKSTN 3          3     4
    ????          5          NULL          1     2
    ????          5          NULL          2     3
    ????          5          NULL          3     4I've tried a number of different things, googled my problem, and no luck yet...
    SELECT     t1.workstation
    ,     SUM(t1.my_value)
    ,     t2.wkstn_name
    ,     t3.my_nbr1
    ,     t3.my_nbr2
    FROM     my_tab1 t1
    ,     my_tab2 t2
    ,     my_tab3 t3
    ...So, what I want is a full outer join of t1 and t2 on workstation, and a cross-join of that with t3. I'm wondering if I can't find any examples of this online because it's not possible....
    Note: I'm stuck dealing with Oracle 8i
    Thanks!!

    Hi,
    The query I posted yesterday is a little more complicated than it needs to be.
    Since my_tab2.workstation is unique, there's no reason to do a separate sub-query like mt1; we can join my_tab1 to my_tab2 and get the SUM all in one sub-query.
    SELECT       foj.workstation
    ,       foj.sum_my_value
    ,       foj.wkstn_name
    ,       mt3.my_nbr1
    ,       mt3.my_nbr2
    FROM       (     -- Begin in-line view foj for full outer join
              SELECT        mt1.workstation
              ,        SUM (mt1.my_value)     AS sum_my_value
              ,        mt2.wkstn_name
              FROM        my_tab1   mt1
              ,        my_tab2   mt2
              WHERE        mt1.workstation     = mt2.workstation (+)
              GROUP BY   mt1.workstation
              ,        mt2.wkstn_name
                    UNION ALL
              SELECT      workstation
              ,      0      AS sum_my_value
              ,      wkstn_name
              FROM      my_tab2
              WHERE      workstation     NOT IN (     -- Begin NOT IN sub-query
                                               SELECT      workstation
                                       FROM      my_tab1
                                       WHERE      workstation     IS NOT NULL
                                     )     -- End NOT IN sub-query
           ) foj     -- End in-line view foj for full outer join
    ,       my_tab3  mt3
    ORDER BY  foj.wkstn_name
    ,       foj.workstation
    ,       mt3.my_nbr1
    ,       mt3.my_nbr2
    ;Thanks for posting the CREATE TABLE and INSERT statements, as well as the very clear desired results!
    user11033437 wrote:
    ... So, what I want is a full outer join of t1 and t2 on workstation, and a cross-join of that with t3. That it, exactly!
    The tricky part is how and when to get SUM (my_value). You might approach this by figuring out exactly what my_tab3 has to be cross-joined to; that is, exactly what should the result set of the full outer join between my_tab1 and my_tab2 look like. To do that, take your desired results, remove the columns that do not come from the full outer join, and remove the duplicate rows. You'll get:
    workstation     sum(my_value)     wkstn_name
    ABCD          30          WKSTN 1          
    A123          35          WKSTN 2          
    B456          0          WKSTN 3          
    ????          5          NULL          So the core of the problem is how to get these results from my_tab1 and my_tab2, which is done in sub-query foj above.
    I tried to use self-documenting names in my code. I hope you can understand it.
    I could spend hours explaining different parts of this query in more detail, but I'm sure I'd waste some of that time explaining things you already understand. If you want an explanation of somthing(s) specific, let me know.

  • Query Of Queries : Error When Trying To Fake Left Outer Join

    Hi there
    I am trying to replicate a left outer join, combining two query of queries using a method I located here
    However, I keep getting an error message..
    Here is the code I am using....
        <cfquery dbtype="query" name="qry">
                    SELECT *
                    FROM returnQry, returnQry2
                    WHERE returnQry.mediumImage = returnQry2.mediumImage
                    ORDER BY returnQry.name   
                </cfquery>
                <cfquery name="returnQry3" dbtype="#application.mx#">
                    SELECT *
                    FROM trackmeanings AS t
                </cfquery>      
               <cfquery dbtype="query" name="endQry">
                    SELECT name,nameRcd,mediumImage, COUNT(sMessage) AS comments
                    FROM qry, returnQry3
                    WHERE qry.name = returnQry3.sNameTrack
                    UNION
                    SELECT name,nameRcd,mediumImage, COUNT(sMessage) AS comments
                    FROM qry, returnQry3
                    WHERE #qry.name# NOT IN (#QuotedValueList(returnQry3.sNameTrack)#)
                    GROUP BY name,nameRcd,mediumImage
                </cfquery>
    When I try to use the query output in a page, i get the error message "Incorrect conditional expression,  Expected one of [like|null|between|in|comparison] condition"
    Would anyone have any ideas?
    Many thanks

    Actually , spoke a little too soon, my query now seems to be outputting duplicates when the value is found on both sides of the union, my group by clause doesnt seem to be eliminating them like it usually does.
    My SELECT code now reads
    <cfquery dbtype="query" name="endQry">
    SELECT name,nameRcd,mediumImage, COUNT(sMessage) AS comments
    FROM qry, returnQry3
    WHERE qry.name = returnQry3.sNameTrack
    GROUP BY name,nameRcd,mediumImage
    UNION
    SELECT name,nameRcd,mediumImage, 0 AS comments
    FROM qry
    WHERE qry.name NOT IN (<cfqueryparam
    value="#returnQry3.sNameTrack#"
    cfsqltype="cf_sql_varchar"
    list="yes"
    />)
    GROUP BY name,nameRcd,mediumImage
    ORDER BY name DESC
    </cfquery>
    and my ouput...is producing duplicates
    <cfoutput query="rc.qryTopTracks" group="name">
    #rc.qryTopTracks.name#
    </cfoutput>
    Would you have any idea of how to eliminate them here?  Thanks

  • Query on Outer join

    Hi all,
    I have a doubt, its written below, pls get me solved
    Inner join:
    SELECT D.DEPTNAME, E.EMPNAME
    FROM DEPARTMENT D, EMPLOYEE E
    WHERE trim(E.DEPTNAME) = D.DEPTNAME
    AND E.EMPNAME = 'ABC'
    TO FETCH ALL THE VALUES FROM DEPARTMENT TABLE BUT ONLY MATCHING
    VALUES FROM EMPLOYEE TABLE, I THINK WE MUST DO AN OUTER JOIN ON
    EMPLOYEE TABLE(OPTIONAL TABLE). SO, QUERY MUST BE SOME THING LIKE AS SHOW BELOW [PLS CORRECT IF I AM WRONG]
    SELECT D.DEPTNAME, E.EMPNAME
    FROM DEPARTMENT D, EMPLOYEE E
    WHERE trim(E.DEPTNAME)(+) = D.DEPTNAME
    AND E.EMPNAME(+) = 'ABC'
    BUT This, is giving me "invalid relational operator"...CAN any one guide me with the query, to get the required results.
    please do remember not to use LEFT OUTER JOIN or RIGHT OUTER JOIN, while rewriting the query.
    Explanation to rewritten query is appreciated.
    Thanks in Advance,
    Vikram Hegde

    Hi,
    I think your first query is enough to give your desired result.
    For your requirement there is no need of outer join.
    In your second query problem is AND E.EMPNAME(+) = 'ABC' You can use (+) only if you are joining two tables. You can not use (+) while you are comparing two values.
    When to use outer join:
    Let say you want to display all records from dept table and there corresponding details from EMP table and few dept_no doesn't have entry in EMP table then
    you can use :
    D.dept_no= E.dept_no(+)
    Regards

  • Toplink outer join issue using ExpressionBuilder getAlllowingNull

    I am trying to retrieve some records through a Toplink outer join expression using ExpressionBuilder's getAllowingNull() with an IN clause but I don't get the correct results.
    In my setup I have the following structure
    CREATE TABLE BOX
    MY_BOX_ID NUMBER(10) PRIMARY KEY
    , MY_CODE VARCHAR2(30) NOT NULL CONSTRAINT u_code UNIQUE
    CREATE TABLE ITEM
    MY_ITEM_ID NUMBER(10) PRIMARY KEY
    ,MY_TYPE NUMBER(6) NOT NULL
    ,BOX_ID REFERENCES BOX(MY_BOX_ID)
    INSERT INTO BOX values (1, '001');
    INSERT INTO ITEM values (1, 1, 1);
    INSERT INTO ITEM values (2, 1, null);
    The Toplink mappings are the most common ones and the code that retrieves the results is
    Vector vals = new Vector();
    vals.add(new String('001'));
    Vector dbList = null;
    try
    DatabaseSession dbSession = getToplinkSession();
    ReadAllQuery query = new ReadAllQuery();
    query.setReferenceClass(Item.class);
    ExpressionBuilder expBuilder = new ExpressionBuilder();
    Expression exp = expBuilder.getAllowingNull("Box").get("myCode").in(vals);
    query.setSelectionCriteria(exp);
    dbList = (Vector) dbSession.executeQuery(query);
    catch(Exception e)
    e.printStackTrace();
    When I run the piece of code Toplink generates the following DB query
    SELECT t1.MY_ITEM_ID, t1.MY_TYPE FROM BOX t0, ITEM t1 WHERE ((t0.MY_CODE IN ('001')) AND (t0.MY_BOX_ID (+) = t1.BOX_ID))
    which returns just the record for which the foreign key is not null
    MY_ITEM_ID MY_TYPE
    1 1
    However I would have expected to get back two records including the one where the foreign key box_id is null. That have happened if the generated SQL would have been:
    SELECT t1.MY_ITEM_ID, t1.MY_TYPE FROM BOX t0, ITEM t1 WHERE ((t0.MY_CODE (+) IN ('001')) AND (t0.MY_BOX_ID (+) = t1.BOX_ID))
    with the outer join operator applied to the query key as well.
    I was wondering if someone could provide some advice on how to get the correct result.
    Thanks for any help,
    Lucian

    Hello,
    Calling builder.getAllowingNull("name_of_field_in_MyJDO"); returns an expression that is not used anywhere in the following code, and so it is not used in the query.
    The addJoinedAttribute(String) on ReadAllQuery will make a simple join expression using the String as the query key. If you want to use an outerJoin instead of the simple inner join created, try:
    readAllQry.addJoinedAttribute(builder.getAllowingNull("name_of_field_in_MyJDO"));
    instead. You will also want to remove any joining statements added at the mapping level made in trying to get this to work, otherwise the inner join specified though those options will still be used.
    Best Regards,
    Chris

  • Removing full outer joins

    Hi All,
    I am creating reports from two fact tables. However, in spite of using only inner joins in RPD, obiee is generating full outer joins between two WITH (sub-query factoring) . Is there a way to enforce inner joins.
    Thanks
    Surya

    872073 wrote:
    All the joins in RPD are inner joins. The query generated is similar as follows. The full outer join is automatically created between SAWITH0 SAWITH1
    WITH
    SAWITH0 AS (SELECT sum(T245.QUANTITY_SOLD) AS c1,
    T161.CHANNEL_DESC AS c2
    FROM
    SH.CHANNELS T161,
    SH.SALES T245
    WHERE ( T161.CHANNEL_ID = T245.CHANNEL_ID )
    GROUP BY T161.CHANNEL_DESC),
    SAWITH1 AS (SELECT sum(T168.UNIT_COST) AS c1,
    T161.CHANNEL_DESC AS c2
    FROM
    SH.CHANNELS T161,
    SH.COSTS T168
    WHERE ( T161.CHANNEL_ID = T168.CHANNEL_ID )
    GROUP BY T161.CHANNEL_DESC)
    SELECT DISTINCT case when SAWITH1.c2 IS NOT NULL then SAWITH1.c2 when SAWITH0.c2 IS NOT NULL then SAWITH0.c2 end AS c1,
    SAWITH0.c1 AS c2,
    SAWITH1.c1 AS c3
    FROM
    SAWITH0 FULL OUTER JOIN SAWITH1 ON SAWITH0.c2 = SAWITH1.c2
    ORDER BY c1
    If I change the underlined FULL OUTER JOIN above to just "JOIN", the query returns what I want.
    Edited by: 872073 on Oct 24, 2012 1:14 PMCheck to see if PERF_PREFER_INTERNAL_STITCH_JOIN was turned off in the DB Features.ini file
    The path to the file is Oracle/Middleware/instances/instance1/config/OracleBIServerComponent/coreapplication_obis1/DBFeatures.INI

  • 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             

  • Query Question: Combine outer join with max() statement

    Hi Folks,
    I have been banging my head on this for a while now and am asking from some advice.
    I have a Project Completion Report that pulls information from a number of tables:
    1) Program (PK: ID)
    2) Project (PK: ID, FK: Program_ID constrained to Program.ID)
    3) Project_Monthly (PK: ID, FK: Project_ID constrained to Project.ID)
    4) Status_Report (PK: ID, FK: Project_ID constrained to Project.ID)
    The Status_Report table has a Record_Date field and holds a BLOB with the status reports for all the projects. In the best of all possible worlds, every project would have a status report, but, obviously, some have no status reports.
    I have been asked to extend the Project Completion Report. It currently shows:
    1) Program Number (Program.Program_Number)
    2) Program Name (Program.Program_Name)
    3) Project (Project.Project_Name)
    4) Projected Completion Date (Project_Monthly.Current_Date_Production)
    We would like to add the latest status report. So I started with something that works in another report, which is to get the ID from the Status_Report table for the record that has the maximum date value in the Record_date that matches the Project in the current Program. But this other query is looking at one program at a time. The Project Completion Report is showing all programs with projects that complete within a certain time frame.
    The requirement is to show all projects that will complete within a time frame and to display the ID of the most recent status report (I use javascript to turn this into a downloadable link). However, whenever I try something like:
    AND Status_Report.Record_Date =
    (select MAX(Status_Report.record_date) from Status_Report
    where Status_Report.ID = Project.ID)I loose all projects that have no status reports associated with them.
    How can I keep all the projects that fulfill the criteria of completing within a specified time frame and add the ID, if it exists, of the most recent status report?
    I thank you for your time and assistance. Please let me know how I can clarify the problem more clearly.
    Yours,
    Petie

    I had thought I finally solved it. Alas, it wasn't yet to be.
    I created a view with the following select statement:
    select p.program_number, p.program_name,
    pj.id as pj_id, pj.project_name, pjm.in_prod_current, pjm.record_date as pjm_record_date,
    prs.id as prs_ID, prs.record_date as prs_record_date
    from program p, project pj, project_monthly pjm,
    project_status_report prs
    where p.id = pj.program_id
    and pj.id = pjm.project_id
    and pj.id = prs.project_id (+);Then, I selected from the view and the project_status_report table, performed an outer join on those (filtered to only the current month's project records) and filtered by the maximum date for each project.
    Here is the resulting query:
    select pc.program_number, pc.pj_id, pc.project_name, pc.in_prod_current,
    pc.pjm_record_date, pc.prs_id
    from project_completion pc,
    project_status_report prs
    where trunc(pjm_record_date, 'mon') = trunc(sysdate,'mon')
    and prs.id = pc.prs_id (+)
    and pc.prs_record_date =
    (select max(mprs.record_date)
    from project_status_report mprs
    where mprs.project_id = pc.pj_id)However, I am still not getting the projects for which there are no status reports.
    Verflixt und zugenaeht!
    It seems that I want to compare based upon the record_date of the status report, but get the ID back. Can I use DECODE for that? Can I get the MAX(prs.record_date), but return only the prs.ID? Because if I include the ID in the select statement, I get too many matches, but if I don't then I don't have the ID, which is needed.
    Any suggestions?
    Thanks, Petie
    Message was edited by:
    Petie

  • Not using Index when SDO_RELATE in Spatial Query is used in LEFT OUTER JOIN

    I want to know for every City (Point geometry) in which Municipality (Polygon geometry) it is.
    Some cities will not be covered by any municipality (as there is no data for it), so its municipality name should be blank in the result
    We have 4942 cities (point geometries)
    and 500 municipalities (polygon geometry)
    SELECT T1.NAME as City, T2.NAME as Municipality
    FROM CITY T1
    LEFT OUTER JOIN MUNICIPALITY T2 ON SDO_RELATE(T1.GEOM, T2.GEOM, 'MASK=ANYINTERACT') = 'TRUE'The explain plan for this query is:
    SELECT STATEMENT
      FILTER
        Filter Predicates
          MDSYS.SDO_RTREE_RELATE(T1.GEOM, T2.GEOM, 'mask=ANYINTERACT querytype=window ') = 'TRUE'
        MERGE JOIN
          TABLE ACCESS              CITY               FULL                            11
          BUFFER                                       SORT                        100605
              TABLE ACCESS          MUNICIPALITY       FULL                            20So the cost is in the BUFFER (whatever that is), it takes +2000 seconds to run this, it is not using the spatial index.
    And we are not getting all rows, but only the ones interacting with a municipality, e.g. 2436 rows.
    But I want all rows, including the ones not interacting with any Municipality.
    When we want only those cities that actually are in a municipality, I use a different query and it will use the index.
    SELECT T1.NAME as City, T2.NAME as Municipality
    FROM CITY T1, MUNICIPALITY T2
    WHERE SDO_RELATE(T1.GEOM, T2.GEOM, 'MASK=ANYINTERACT') = 'TRUE'I get (only) 2436 rows (as expected) in 5 seconds (it is fast) and the explain plan shows it is using the spatial index.
    But in this case, I am not getting any cities not inside any municipality (of course)
    SELECT STATEMENT
       NESTED LOOPS
          TABLE ACCESS                   MUNICIPALITY       FULL                22
          TABLE ACCESS                   CITY               BY INDEX ROWID      22
             DOMAIN INDEX                CITY_SDX                                0
                Access Predicates
                   MDSYS.SDO_RTREE_RELATE(T1.GEOM, T2.GEOM, 'mask=ANYINTERACT querytype=window ') = 'TRUE'I always thought a LEFT OUTER JOIN would return all rows from the Table, whatever happens in the next,
    but it seems the query has been rewritten so that it is now using a Filter Predicate in the end, which filters those geometries having no interaction.
    As an example I also do thing alphanumerically, I do get 4942 rows, including the ones which have no Municipality name.
    In this case the names must match, so its only for testing if the LEFT OUTER JOIN returns stuff correctly, which it does in this case.
    SELECT T1.NAME as City, T2.NAME as Municipality
    FROM CITY T1
    LEFT OUTER JOIN MUNICIPALITY T2 ON T1.NAME = T2.NAMEIs this an Oracle Spatial bug, e.g. not return 4942 rows, but only 2436 rows on the first query?
    Note all tests performed on Oracle 11g R2 (11.2.0.1.0)

    Patrick,
    Even so, your geoms in the relate were the wrong way around.
    Also, I don't recall you saying (or showing) that you wanted the municipality geometry returned. Still,
    no matter, easy to do.
    Here are some additional suggestions. I don't have your data so I have had to use some of my own.
    set serveroutput on timing on autotrace on
    SELECT T1.SPECIES as City,
           (SELECT T2.ADMIN_NAME FROM AUSTRALIAN_STATES T2 WHERE SDO_ANYINTERACT(T2.GEOM, SDO_GEOM.SDO_BUFFER(T1.GEOM,10000,0.5,'UNIT=M')) = 'TRUE') as Municipality,
           (SELECT T2.GEOM       FROM AUSTRALIAN_STATES T2 WHERE SDO_ANYINTERACT(T2.GEOM, SDO_GEOM.SDO_BUFFER(T1.GEOM,10000,0.5,'UNIT=M')) = 'TRUE') as geom
      FROM GUTDATA T1;
    762 rows selected
    Elapsed: 00:00:21.656
    Plan hash value: 2160035213
    | Id  | Operation                   | Name                       | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT            |                            |   762 | 49530 |     5   (0)| 00:00:01 |
    |   1 |  TABLE ACCESS BY INDEX ROWID| AUSTRALIAN_STATES          |     1 |   115 |     0   (0)| 00:00:01 |
    |*  2 |   DOMAIN INDEX              | AUSTRALIAN_STATES_GEOM_SPX |       |       |     0   (0)| 00:00:01 |
    |   3 |  TABLE ACCESS BY INDEX ROWID| AUSTRALIAN_STATES          |     1 |   115 |     0   (0)| 00:00:01 |
    |*  4 |   DOMAIN INDEX              | AUSTRALIAN_STATES_GEOM_SPX |       |       |     0   (0)| 00:00:01 |
    |   5 |  TABLE ACCESS FULL          | GUTDATA                    |   762 | 49530 |     5   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - access("MDSYS"."SDO_ANYINTERACT"("T2"."GEOM","SDO_GEOM"."SDO_BUFFER"(:B1,10000,0.5,'UNIT=M'))='TRUE')
       4 - access("MDSYS"."SDO_ANYINTERACT"("T2"."GEOM","SDO_GEOM"."SDO_BUFFER"(:B1,10000,0.5,'UNIT=M'))='TRUE')
       Statistics
                   7  user calls
               24576  physical read total bytes
                   0  physical write total bytes
                   0  spare statistic 3
                   0  commit cleanout failures: cannot pin
                   0  TBS Extension: bytes extended
                   0  total number of times SMON posted
                   0  SMON posted for undo segment recovery
                   0  SMON posted for dropping temp segment
                   0  segment prealloc tasksThe above can look messy as you add more (SELECT ...) attributes, but is is fast (though can't use in Materialized Views).
    /* The set of all cities not in municipalities */
    SELECT T1.SPECIES                 as City,
           cast(null as varchar2(42)) as municipality,
           cast(null as sdo_geometry) as geom
      FROM GUTDATA T1
    WHERE NOT EXISTS (SELECT 1
                         FROM AUSTRALIAN_STATES T2
                        WHERE SDO_ANYINTERACT(T2.GEOM, SDO_GEOM.SDO_BUFFER(T1.GEOM,10000,0.5,'UNIT=M')) = 'TRUE')
    UNION ALL
    /* The set of all cities in municipalities */
    SELECT T1.SPECIES    as City,
           T2.ADMIN_NAME as Municipality,
           T2.GEOM       as geom
      FROM GUTDATA T1
           INNER JOIN
           AUSTRALIAN_STATES T2 ON (SDO_ANYINTERACT(T2.GEOM, SDO_GEOM.SDO_BUFFER(T1.GEOM,10000,0.5,'UNIT=M')) = 'TRUE');
    762 rows selected
    Elapsed: 00:00:59.953
    Plan hash value: 2854682795
    | Id  | Operation           | Name                       | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT    |                            |    99 | 13450 |    38  (87)| 00:00:01 |
    |   1 |  UNION-ALL          |                            |       |       |            |          |
    |*  2 |   FILTER            |                            |       |       |            |          |
    |   3 |    TABLE ACCESS FULL| GUTDATA                    |   762 | 49530 |     5   (0)| 00:00:01 |
    |*  4 |    DOMAIN INDEX     | AUSTRALIAN_STATES_GEOM_SPX |       |       |     0   (0)| 00:00:01 |
    |   5 |   NESTED LOOPS      |                            |    61 | 10980 |    33   (0)| 00:00:01 |
    |   6 |    TABLE ACCESS FULL| AUSTRALIAN_STATES          |     8 |   920 |     3   (0)| 00:00:01 |
    |*  7 |    TABLE ACCESS FULL| GUTDATA                    |     8 |   520 |     4   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - filter( NOT EXISTS (SELECT 0 FROM "AUSTRALIAN_STATES" "T2" WHERE "MDSYS"."SDO_ANYINTERACT"("T2"."GEOM","SDO_GEOM"."SDO_BUFFER"(:B1,10000,0.5,'UNIT=M'))='TRUE'))
       4 - access("MDSYS"."SDO_ANYINTERACT"("T2"."GEOM","SDO_GEOM"."SDO_BUFFER"(:B1,10000,0.5,'UNIT=M'))='TRUE')
       7 - filter("MDSYS"."SDO_ANYINTERACT"("T2"."GEOM","SDO_GEOM"."SDO_BUFFER"("T1"."GEOM",10000,0.5,'UNIT=M'))='TRUE')
       Statistics
                   7  user calls
              131072  physical read total bytes
                   0  physical write total bytes
                   0  spare statistic 3
                   0  commit cleanout failures: cannot pin
                   0  TBS Extension: bytes extended
                   0  total number of times SMON posted
                   0  SMON posted for undo segment recovery
                   0  SMON posted for dropping temp segment
                   0  segment prealloc tasksMuch slower but Materialized View friendly.
    This one is a bit more "natural" but still slower than the first.
    set serveroutput on timing on autotrace on
    /* The set of all cities in municipalities */
    WITH municipal_cities As (
      SELECT T1.ID         as City,
             T2.ADMIN_NAME as Municipality,
             T2.GEOM       as geom
        FROM GUTDATA T1
             INNER JOIN
             AUSTRALIAN_STATES T2 ON (SDO_ANYINTERACT(T2.GEOM, SDO_GEOM.SDO_BUFFER(T1.GEOM,10000,0.5,'UNIT=M')) = 'TRUE')
    SELECT T1.ID           as City,
           T2.Municipality as Municipality,
           T2.GEOM         as geom
      FROM GUTDATA          T1
           LEFT OUTER JOIN
           municipal_cities T2
           ON (T2.CITY = T1.ID);
    762 rows selected
    Elapsed: 00:00:50.228
    Plan hash value: 745978991
    | Id  | Operation             | Name              | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT      |                   |   762 | 44196 |    36   (3)| 00:00:01 |
    |*  1 |  HASH JOIN RIGHT OUTER|                   |   762 | 44196 |    36   (3)| 00:00:01 |
    |   2 |   VIEW                |                   |    61 |  3294 |    33   (0)| 00:00:01 |
    |   3 |    NESTED LOOPS       |                   |    61 | 10980 |    33   (0)| 00:00:01 |
    |   4 |     TABLE ACCESS FULL | AUSTRALIAN_STATES |     8 |   920 |     3   (0)| 00:00:01 |
    |*  5 |     TABLE ACCESS FULL | GUTDATA           |     8 |   520 |     4   (0)| 00:00:01 |
    |   6 |   INDEX FAST FULL SCAN| GUTDATA_ID_PK     |   762 |  3048 |     2   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - access("T2"."CITY"(+)="T1"."ID")
       5 - filter("MDSYS"."SDO_ANYINTERACT"("T2"."GEOM","SDO_GEOM"."SDO_BUFFER"("T1"."GEOM",10000,0.5,'UNIT=M'))='TRUE')
       Statistics
                   7  user calls
               49152  physical read total bytes
                   0  physical write total bytes
                   0  spare statistic 3
                   0  commit cleanout failures: cannot pin
                   0  TBS Extension: bytes extended
                   0  total number of times SMON posted
                   0  SMON posted for undo segment recovery
                   0  SMON posted for dropping temp segment
                   0  segment prealloc tasksFinally, the Pièce de résistance: trick the LEFT OUTER JOIN operator...
    set serveroutput on timing on autotrace on
    SELECT T1.SPECIES    as City,
           T2.ADMIN_NAME as Municipality,
           T2.GEOM       as geom
      FROM GUTDATA           T1
           LEFT OUTER JOIN
           AUSTRALIAN_STATES T2
           ON (t2.admin_name = to_char(t1.ID) OR
               SDO_ANYINTERACT(T2.GEOM, SDO_GEOM.SDO_BUFFER(T1.GEOM,10000,0.5,'UNIT=M')) = 'TRUE');
    762 rows selected
    Elapsed: 00:00:50.273
    Plan hash value: 158854308
    | Id  | Operation           | Name              | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT    |                   |   762 | 92964 |  2294   (1)| 00:00:28 |
    |   1 |  NESTED LOOPS OUTER |                   |   762 | 92964 |  2294   (1)| 00:00:28 |
    |   2 |   TABLE ACCESS FULL | GUTDATA           |   762 | 49530 |     5   (0)| 00:00:01 |
    |   3 |   VIEW              |                   |     1 |    57 |     3   (0)| 00:00:01 |
    |*  4 |    TABLE ACCESS FULL| AUSTRALIAN_STATES |     1 |   115 |     3   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       4 - filter("T2"."ADMIN_NAME"=TO_CHAR("T1"."ID") OR
                  "MDSYS"."SDO_ANYINTERACT"("T2"."GEOM","SDO_GEOM"."SDO_BUFFER"("T1"."GEOM",10000,0.5,'UNIT=M'))='TRUE')
       Statistics
                   7  user calls
                   0  physical read total bytes
                   0  physical write total bytes
                   0  spare statistic 3
                   0  commit cleanout failures: cannot pin
                   0  TBS Extension: bytes extended
                   0  total number of times SMON posted
                   0  SMON posted for undo segment recovery
                   0  SMON posted for dropping temp segment
                   0  segment prealloc tasksTry these combinations to see what works for you.
    Interestingly, for me, the following returns absolutely nothing.
    SELECT T1.SPECIES    as City,
           T2.ADMIN_NAME as Municipality
      FROM GUTDATA           T1
           LEFT OUTER JOIN
           AUSTRALIAN_STATES T2
           ON (SDO_ANYINTERACT(T2.GEOM, SDO_GEOM.SDO_BUFFER(T1.GEOM,10000,0.5,'UNIT=M')) = 'TRUE')
    MINUS
    SELECT T1.SPECIES    as City,
           T2.ADMIN_NAME as Municipality
      FROM GUTDATA           T1
           LEFT OUTER JOIN
           AUSTRALIAN_STATES T2
           ON (t2.admin_name =  to_char(t1.ID) OR
               SDO_ANYINTERACT(T2.GEOM, SDO_GEOM.SDO_BUFFER(T1.GEOM,10000,0.5,'UNIT=M')) = 'TRUE');(I leave it to you to see if you can see why as the LEFT OUTER JOIN seems to be working correctly for me but I am not going to dedicate time to detailed checking of results.)
    Note all tests performed on Oracle 11g R2 (11.2.0.1.0)
    If you get the answer you want: mark the post as answered to assign points.
    regards
    Simon

  • How to do outer join select query for an APEX report

    Hello everyone,
    I am Ann.
    I have one select statement that calculate the statistics for one month(October 2012 in this example)
    select ph.phase_number
    , sum ( (case
    WHEN ph.date_finished IS NULL OR ph.date_finished > last_day(TO_DATE('Oct 2012','MON YYYY'))
    THEN last_day(TO_DATE('Oct 2012','MON YYYY'))
    ELSE ph.date_finished
    END )
    - ph.date_started + 1) / count(def.def_id) as avg_days
    from phase_membership ph
    inner join court_engagement ce on ph.mpm_eng_id = ce.engagement_id
    inner join defendant def on ce.defendant_id = def.def_id
    where def.active = 1
    and ph.date_started <= last_day(TO_DATE('Oct 2012','MON YYYY'))
    and ph.active = 1
    and UPPER(ce.court_name) LIKE '%'
    group by rollup(phase_number)
    Result is as below
    Phase_Number     AVG_DAYS
    Phase One     8.6666666666666667
    Phase Two     14.6
    Phase Three     12
         11.4615365
    I have other select list mainly list the months between two date value.
    select to_char(which_month, 'MON YYYY') as display_month
    from (
    select add_months(to_date('Aug 2012','MON YYYY'), rownum-1) which_month
    from all_objects
    where
    rownum <= months_between(to_date('Oct 2012','MON YYYY'), add_months(to_date('Aug 2012','MON YYYY'), -1))
    order by which_month )
    Query result is as below
    DISPLAY_MONTH
    AUG 2012
    SEP 2012
    OCT 2012
    Is there any way that I can join these two select statement above to generate a result like:
    Month          Phase Number     Avg days
    Aug 2012     Phase One     8.666
    Sep 2012     Phase One     7.66
    Oct 2012     Phase One     5.66
    Aug 2012     Phase Two     8.666
    Sep 2012     Phase Two     7.66
    Oct 2012     Phase Two     5.66
    Aug 2012     Phase Three     8.666
    Sep 2012     Phase Three     7.66
    Oct 2012     Phase Three     5.66
    Or
    Month          Phase Number     Avg days
    Aug 2012     Phase One     8.666
    Aug 2012     Phase Two     7.66
    Aug 2012     Phase Three     5.66
    Sep 2012     Phase One     8.666
    Sep 2012     Phase Two     7.66
    Sep 2012     Phase Three     5.66
    Oct 2012     Phase One     8.666
    Oct 2012     Phase Two     7.66
    Oct 2012     Phase Three     5.66
    And it can be order by either Phase Number or Month.
    My other colleague suggest I should use an left outer join but after trying so many ways, I am still stuck.
    One of the select I tried is
    select a.display_month,b.* from (
    select to_char(which_month, 'MON YYYY') as display_month
    from (
    select add_months(to_date('Aug 2012','MON YYYY'), rownum-1) which_month
    from all_objects
    where
    rownum <= months_between(to_date('Oct 2012','MON YYYY'), add_months(to_date('Aug 2012','MON YYYY'), -1))
    order by which_month )) a left outer join
    ( select to_char(ph.date_finished,'MON YYYY') as join_month, ph.phase_number
    , sum ( (case
    WHEN ph.date_finished IS NULL OR ph.date_finished > last_day(TO_DATE(a.display_month,'MON YYYY'))
    THEN last_day(TO_DATE(a.display_month,'MON YYYY'))
    ELSE ph.date_finished
    END )
    - ph.date_started + 1) / count(def.def_id) as avg_days
    from phase_membership ph
    inner join court_engagement ce on ph.mpm_eng_id = ce.engagement_id
    inner join defendant def on ce.defendant_id = def.def_id
    where def.active = 1
    and ph.date_started <= last_day(TO_DATE(a.display_month,'MON YYYY'))
    and ph.active = 1
    and UPPER(ce.court_name) LIKE '%'
    group by to_char(ph.date_finished,'MON YYYY') , rollup(phase_number)) b
    on a.display_month = b.join_month
    but then I get an error
    SQL Error: ORA-00904: "A"."DISPLAY_MONTH": invalid identifier
    I need to display a report on APEX with option for people to download at least CSV format.
    I already have 1 inteactive report in the page, so don’t think can add another interactive report without using the iframe trick.
    If any of you have any ideas, please help.
    Thanks a lot.
    Ann

    First of all, a huge thanks for following this Frank.
    I have just started working here, I think the Oracle version is 11g, but not sure.
    To run Oracle APEX version 4, I think they must have at least 10g R2.
    This report is a bit challenging for me.I has never worked with PARTITION before.
    About the select query you suggested, I run , and it seems working fine, but if I try this,
    it return error ORA-01843: not a valid month
    DEFINE startmonth = "Aug 2012";
    DEFINE endmonth   = "Oct 2012";
    WITH     all_months     AS
         select add_months(to_date('&startmonth','MON YYYY'), rownum-1) AS which_month
         ,      add_months(to_date('&startmonth','MON YYYY'), rownum  ) AS next_month
         from all_objects
         where
         rownum <= months_between(to_date('&endmonth','MON YYYY'), add_months(to_date('&startmonth','MON YYYY'), -1))
    select TO_CHAR (am.which_month, 'Mon YYYY')     AS month
    ,      ph.phase_number
    , sum ( (case
    WHEN ph.date_finished IS NULL OR ph.date_finished > last_day(TO_DATE(am.which_month,'MON YYYY'))
    THEN last_day(TO_DATE(am.which_month,'MON YYYY'))
    ELSE ph.date_finished
    END )
    - ph.date_started + 1) / count(def.def_id) as avg_days
    FROM           all_months          am
    LEFT OUTER JOIN  phase_membership  ph  PARTITION BY (ph.phase_number)
                                        ON  am.which_month <= ph.date_started
                               AND am.next_month  >  ph.date_started
                               AND ph.date_started <= last_day(TO_DATE(am.which_month,'MON YYYY'))  -- May not be needed
                               AND ph.active = 1
    LEFT OUTER join  court_engagement  ce  on  ph.mpm_eng_id = ce.engagement_id
                                        and ce.court_name IS NOT NULL  -- or something involving LIKE
    LEFT OUTER join  defendant         def on  ce.defendant_id = def.def_id
                                        AND def.active = 1
    group by rollup(phase_number, am.which_month)
    ORDER BY  am.which_month
    ,            ph.phase_number
    ;Here is the shorted versions of the three tables:
    A_DEFENDANT, A_ENGAGEMENT, A_PHASE_MEMBERSHIP
    CREATE TABLE "A_DEFENDANT"
        "DEF_ID"     NUMBER NOT NULL ENABLE,
        "FIRST_NAME" VARCHAR2(50 BYTE),
        "SURNAME"    VARCHAR2(20 BYTE) NOT NULL ENABLE,
        "DOB" DATE NOT NULL ENABLE,
        "ACTIVE" NUMBER(2,0) DEFAULT 1 NOT NULL ENABLE,
        CONSTRAINT "A_DEFENDANT_PK" PRIMARY KEY ("DEF_ID"))
    Sample Data
    Insert into A_DEFENDANT (DEF_ID,FIRST_NAME,SURNAME,DOB,ACTIVE) values (101,'Joe','Bloggs',to_date('12/12/99','DD/MM/RR'),1);
    Insert into A_DEFENDANT (DEF_ID,FIRST_NAME,SURNAME,DOB,ACTIVE) values (102,'John','Smith',to_date('20/05/00','DD/MM/RR'),1);
    Insert into A_DEFENDANT (DEF_ID,FIRST_NAME,SURNAME,DOB,ACTIVE) values (103,'Jane','Black',to_date('15/02/98','DD/MM/RR'),1);
    Insert into A_DEFENDANT (DEF_ID,FIRST_NAME,SURNAME,DOB,ACTIVE) values (104,'Minnie','Mouse',to_date('13/12/88','DD/MM/RR'),0);
    Insert into A_DEFENDANT (DEF_ID,FIRST_NAME,SURNAME,DOB,ACTIVE) values (105,'Daisy','Duck',to_date('05/08/00','DD/MM/RR'),1);
    CREATE TABLE "A_ENGAGEMENT"
        "ENGAGEMENT_ID" NUMBER NOT NULL ENABLE,
        "COURT_NAME"    VARCHAR2(50 BYTE) NOT NULL ENABLE,
        "DATE_REFERRED" DATE,
        "DETERMINATION_HEARING_DATE" DATE,
        "DATE_JOINED_COURT" DATE,
        "DATE_TREATMENT_STARTED" DATE,
        "DATE_TERMINATED" DATE,
        "TERMINATION_TYPE" VARCHAR2(50 BYTE),
        "ACTIVE"           NUMBER(2,0) DEFAULT 1 NOT NULL ENABLE,
        "DEFENDANT_ID"     NUMBER,
        CONSTRAINT "A_ENGAGEMENT_PK" PRIMARY KEY ("ENGAGEMENT_ID"))
    Insert into A_ENGAGEMENT (ENGAGEMENT_ID,COURT_NAME,DATE_REFERRED,DETERMINATION_HEARING_DATE,DATE_JOINED_COURT,DATE_TREATMENT_STARTED,DATE_TERMINATED,TERMINATION_TYPE,ACTIVE,DEFENDANT_ID) values (1,'AA',to_date('12/08/12','DD/MM/RR'),null,to_date('12/08/12','DD/MM/RR'),null,null,null,1,101);
    Insert into A_ENGAGEMENT (ENGAGEMENT_ID,COURT_NAME,DATE_REFERRED,DETERMINATION_HEARING_DATE,DATE_JOINED_COURT,DATE_TREATMENT_STARTED,DATE_TERMINATED,TERMINATION_TYPE,ACTIVE,DEFENDANT_ID) values (2,'BB',to_date('01/09/12','DD/MM/RR'),null,to_date('02/09/12','DD/MM/RR'),null,null,null,1,102);
    Insert into A_ENGAGEMENT (ENGAGEMENT_ID,COURT_NAME,DATE_REFERRED,DETERMINATION_HEARING_DATE,DATE_JOINED_COURT,DATE_TREATMENT_STARTED,DATE_TERMINATED,TERMINATION_TYPE,ACTIVE,DEFENDANT_ID) values (3,'AA',to_date('02/09/12','DD/MM/RR'),null,to_date('15/09/12','DD/MM/RR'),null,null,null,1,103);
    Insert into A_ENGAGEMENT (ENGAGEMENT_ID,COURT_NAME,DATE_REFERRED,DETERMINATION_HEARING_DATE,DATE_JOINED_COURT,DATE_TREATMENT_STARTED,DATE_TERMINATED,TERMINATION_TYPE,ACTIVE,DEFENDANT_ID) values (4,'BB',to_date('01/10/12','DD/MM/RR'),null,to_date('02/10/12','DD/MM/RR'),null,null,null,1,105);
    CREATE TABLE "A_PHASE_MEMBERSHIP"
        "MPM_ID"       NUMBER NOT NULL ENABLE,
        "MPM_ENG_ID"   NUMBER NOT NULL ENABLE,
        "PHASE_NUMBER" VARCHAR2(50 BYTE),
        "DATE_STARTED" DATE NOT NULL ENABLE,
        "DATE_FINISHED" DATE,
        "NOTES"  VARCHAR2(2000 BYTE),
        "ACTIVE" NUMBER(2,0) DEFAULT 1 NOT NULL ENABLE,
        CONSTRAINT "A_PHASE_MEMBERSHIP_PK" PRIMARY KEY ("MPM_ID"))
    Insert into A_PHASE_MEMBERSHIP (MPM_ID,MPM_ENG_ID,PHASE_NUMBER,DATE_STARTED,DATE_FINISHED,NOTES,ACTIVE) values (1,1,'PHASE ONE',to_date('15/09/12','DD/MM/RR'),to_date('20/09/12','DD/MM/RR'),null,1);
    Insert into A_PHASE_MEMBERSHIP (MPM_ID,MPM_ENG_ID,PHASE_NUMBER,DATE_STARTED,DATE_FINISHED,NOTES,ACTIVE) values (2,1,'PHASE TWO',to_date('21/09/12','DD/MM/RR'),to_date('29/09/12','DD/MM/RR'),null,1);
    Insert into A_PHASE_MEMBERSHIP (MPM_ID,MPM_ENG_ID,PHASE_NUMBER,DATE_STARTED,DATE_FINISHED,NOTES,ACTIVE) values (3,2,'PHASE ONE',to_date('12/09/12','DD/MM/RR'),null,null,1);
    Insert into A_PHASE_MEMBERSHIP (MPM_ID,MPM_ENG_ID,PHASE_NUMBER,DATE_STARTED,DATE_FINISHED,NOTES,ACTIVE) values (4,3,'PHASE ONE',to_date('20/09/12','DD/MM/RR'),to_date('01/10/12','DD/MM/RR'),null,1);
    Insert into A_PHASE_MEMBERSHIP (MPM_ID,MPM_ENG_ID,PHASE_NUMBER,DATE_STARTED,DATE_FINISHED,NOTES,ACTIVE) values (5,3,'PHASE TWO',to_date('02/10/12','DD/MM/RR'),to_date('15/10/12','DD/MM/RR'),null,1);
    Insert into A_PHASE_MEMBERSHIP (MPM_ID,MPM_ENG_ID,PHASE_NUMBER,DATE_STARTED,DATE_FINISHED,NOTES,ACTIVE) values (6,4,'PHASE ONE',to_date('03/10/12','DD/MM/RR'),to_date('10/10/12','DD/MM/RR'),null,1);
    Insert into A_PHASE_MEMBERSHIP (MPM_ID,MPM_ENG_ID,PHASE_NUMBER,DATE_STARTED,DATE_FINISHED,NOTES,ACTIVE) values (7,3,'PHASE THREE',to_date('17/10/12','DD/MM/RR'),null,null,0);
    Insert into A_PHASE_MEMBERSHIP (MPM_ID,MPM_ENG_ID,PHASE_NUMBER,DATE_STARTED,DATE_FINISHED,NOTES,ACTIVE) values (8,1,'PHASE THREE',to_date('30/09/12','DD/MM/RR'),to_date('16/10/12','DD/MM/RR'),null,1);
    The requirements are:
    The user must be able to request the extract for one or more calendar months, e.g.
    May 2013
    May 2013 – Sep 2013.
    The file must contain a separate row for each calendar month in the requested range. Each row must contain the statistics computed for that calendar month.
    The file must also include a row of totals.
    The user must be able to request the extract for either Waitakere or Auckland or Consolidated (both courts’ statistics accumulated).
    Then the part that I am stuck is
    For each monitoring phase:
    Phase name (e.g. “Phase One”)
    Avg_time_in_phase_all_particip
    for each phase name,
    Add up days in each “phase name” Monitoring Phase, calculated as:
    If Monitoring Phase.Date Finished is NULL or > month end date,
    +(*Month end date* Minus Monitoring Phase.Date Started Plus 1)+
    Otherwise (phase is complete)
    +(Monitoring Phase.Date Finished Minus Monitoring Phase.Date Started Plus 1.)+
    Divide by the numbers of all participants who have engaged in “phase name”.
    This is the words of the Business Analyst,
    I try to do as required but still struggle to identify end_month for the above formula to display for the range of months.
    Of course, I can write two nested cursor. The first one run the list of month, then for each month, run the parameterised report.
    But I prefer if possible just use SQL statements, or at least a PL/SQL but return a query.
    With this way, I can create an APEX report, and use their CSV Extract function.
    Yes, you are right, court_name is one of the selection parameters.
    And the statistics is not exactly for one month. It is kind of trying to identify all phases that are running through the specified month (even phase.date_started is before the month start).
    This is the reason why I put the condition AND ph.date_started <= last_day(TO_DATE('Oct 2012','MON YYYY')) (otherwise I get negative avg_days)
    User can choose either one court "AA" or "BB" or combined which is all figures.
    Sorry for bombarding you a lot of information.
    Thanks a lot, again.
    Edited by: Ann586341 on Oct 29, 2012 9:57 PM
    Edited by: Ann586341 on Oct 29, 2012 9:59 PM

  • Outer Join with the query

    I have written the below query, our requirement is, Some employees have "Transport Allowance" but not "Project Allowance". For this, I tried to use OUTER JOIN with this query. But this query takes long time and failed. The following query works fine if the employee has both "Transport Allowance" and "Project Allowance" (without outer join) Now, I also need to retrieve the employees who have "Transport Allowance" but not "Project Allowance". How can I retrieve it?
    SELECT DISTINCT papf.employee_number
    , peev.screen_entry_value Transport_Allowance
    ,peev1.screen_entry_value Project_Allowance
    FROM apps.per_all_people_f papf
    ,apps.per_all_assignments_f paaf
    ,apps.pay_element_types_x petf
    ,apps.pay_element_types_x petf1
    ,apps.pay_element_types_x petf2
    ,apps.pay_element_entries_f peef
    ,apps.pay_element_entries_f peef1
    ,apps.pay_element_entries_f peef2
    ,apps.pay_element_entry_values_x peev
    ,apps.pay_element_entry_values_x peev1
    ,apps.pay_element_entry_values_x peev2
    ,apps.pay_input_values_x pivf
    ,apps.pay_input_values_x pivf1
    ,apps.pay_input_values_x pivf2
    WHERE
    papf.person_id = paaf.person_id
    AND paaf.assignment_id = peef.assignment_id
    AND paaf.assignment_id = peef1.assignment_id
    AND paaf.business_group_id = papf.business_group_id
    --Transport Allowance
    AND peef.element_entry_id = peev.element_entry_id
    AND petf.element_Name = 'Transport Allowance'
    AND pivf.element_type_id =petf.element_type_id
    AND pivf.name = 'Allowance'
    AND peev.input_value_id= pivf.input_value_id
    --Project Allowance
    AND peef1.element_entry_id = peev1.element_entry_id
    AND petf1.element_Name = "Project Allowance'
    AND pivf1.element_type_id = petf1.element_type_id
    AND pivf1.name = 'Allowance'
    AND peev1.input_value_id = pivf1.input_value_id
    AND (SYSDATE BETWEEN peev.effective_start_date AND peev.effective_end_date)
    AND (SYSDATE BETWEEN peev1.effective_start_date AND peev1.effective_end_date)
    AND (SYSDATE BETWEEN papf.effective_start_date AND papf.effective_end_date)
    ORDER BY papf.employee_number
    Thanks in advance.

    I am using sames tables with alias to retrieve the columns values from the same table.
    Here is my query.
    SELECT DISTINCT papf.employee_number
    , peev.screen_entry_value Transport_Allowance
    ,peev1.screen_entry_value Project_Allowance
    FROM apps.per_all_people_f papf
    ,apps.per_all_assignments_f paaf
    ,apps.pay_element_types_x petf
    ,apps.pay_element_types_x petf1
    ,apps.pay_element_entries_f peef
    ,apps.pay_element_entries_f peef1
    ,apps.pay_element_entry_values_x peev
    ,apps.pay_element_entry_values_x peev1
    ,apps.pay_input_values_x pivf
    ,apps.pay_input_values_x pivf1
    WHERE
    papf.person_id = paaf.person_id
    AND paaf.assignment_id = peef.assignment_id
    AND paaf.assignment_id = peef1.assignment_id
    AND paaf.business_group_id = papf.business_group_id
    --Transport Allowance
    AND peef.element_entry_id = peev.element_entry_id
    AND petf.element_Name = 'Transport Allowance'
    AND pivf.element_type_id =petf.element_type_id
    AND pivf.name = 'Allowance'
    AND peev.input_value_id= pivf.input_value_id
    --Project Allowance
    AND peef1.element_entry_id = peev1.element_entry_id
    AND petf1.element_Name = "Project Allowance'
    AND pivf1.element_type_id = petf1.element_type_id
    AND pivf1.name = 'Allowance'
    AND peev1.input_value_id = pivf1.input_value_id
    AND (SYSDATE BETWEEN peev.effective_start_date AND peev.effective_end_date)
    AND (SYSDATE BETWEEN peev1.effective_start_date AND peev1.effective_end_date)
    AND (SYSDATE BETWEEN papf.effective_start_date AND papf.effective_end_date)
    ORDER BY papf.employee_number
    Thanks in advance.

  • Invalid combinations of joins involving outer joins

    Hi all, I have the following problem
    Scenario: I created 6 custom folders:
    Tasks (with measures)
    Type
    Criticity
    Status
    Owners
    Assignees
    The first folder is used to retrieve how many tasks (COUNT(tasks)) have a particular type or status or a combination between them, and the others 5 are dimensions.
    I create 6 joins starting always from the dimensions in this way (radio buttons):
    Detail item values always exist in master folder (Typical)
    Outer join on detail
    where the master is always a dimension and the detail is always the custom folder with the measures.
    I put the outer join on the custom folder with the measures because I want to show '0' in case I don't have any record on this folder for a specific attribute on a dimension (the join fails).
    I saw that if I put the outer join on the master (dimensions), when the join fails I don't see at all the information regarding that particular dimension.
    For example
    I select 2 folder: Tasks and Assignee
    join: Tasks.task_id (+) = Assignee.task_id
    Result:
    TASK ASSIGNEE
    10 Mr. A
    20 Mr. B
    30 Mr. C
    0 Mr. D
    Just to make a test, If I change the join on Administrator putting :
    Detail item values might not exist in master folder
    Outer join on master
    ...the result is this
    TASK ASSIGNEE
    10 Mr. A
    20 Mr. B
    30 Mr. C
    ...I don't see the last record.
    The customer asked to see always the record with task =0 (if exists), so I joined all the custom folders as I expalned above, but when I try to link (on Discoverer Plus) more than two tasks I have the following error:
    Invalid combinations of joins involving outer joins
    So, my question is this: how can I avoid this error ? Does it exist any trick or another way to link the custom folders (showing always the records with '0' when the join doesn't retrieve nothing ) ?
    Thanks in advance
    Alex

    Well I will take a stab at answering this. The problem is not knowing what is in your custom folders. Also not knowing the specifics on your Discoverer Join definitions. On something like this you may be better going to Oracle support, since they can start a Web Conference and see exactly what you see, and can check out the various possibilities. All we here can do is make guesses, and the guesses could be wrong.
    You do have to be careful in your join definitions in Discoverer. You have to pick the correct table as the Master table, and the correct table as the Detail table. Mess that up and you can mess yourself up. So my first though is check your join definition. Sounds like you want assigned to be the master table. Then tasks would be the detail table.
    Then you want to pick the option that detail items might not exist in master. Which it looks like you have done.
    Then for the other options, Oracle, in my mind, does the opposite of what I would think to pick. If you pick OUTER JOIN ON DETAIL, that will include the Master items with no detail items. So that is what you need to pick.
    Looks like you did the OUTER JOIN ON MASTER, which means will include detail items with no master. Since you had a master with no detail, it will not show, and that is why the Mr. D does not show.
    I always have to do the help on this because it is opposite of what I would expect - my mind thinks outer join on master should include all masters. Nope, it has to be the outer join on detail to do that.
    The master with no detail will probably show a NULL value in the column for the detail, instead of 0. You could convert the null value to display as a 0.
    Hope this helps a bit. Just remember that I am guessing/speculating on a possible cause.
    John Dickey

  • SCORE(n) returning zero values in an outer join query

    Hello all,
    Is there any way to get a query that contains an outer join to return proper scores. I couldn't find out why this was happening in my query, but I'm getting a score values of 0 on most results.
    Below are queries with result sets. As you can see the results that are scoring in the second query are scoring correctly, but only two have scores.
    - - - Query 1, no outer join - - -
    SELECT DISTINCT SCORE(0) AS scr,
    file_repository.file_id,
    file_repository.file_title
    FROM file_repository
    WHERE CONTAINS(index_url,'SYN(dui,a_thesaurus)', 0) > 0
    ORDER BY scr ASC
    SCR FILE_ID FILE_TITLE
    7 136 Prisoners
    7 240 Drug booklet
    8 64 Communications
    8 146 Rates
    8 168 Vehicle Collisions
    8 206 document4
    14 207 document5
    14 211 document5
    15 74 Diplomatic Personnel
    22 214 documentB
    30 81 DUI and PCA Offences
    - - - Query 2, with outer join - - -
    SELECT DISTINCT SCORE(0) AS scr,
    file_repository.file_id,
    file_repository.file_title
    FROM file_repository, file_security
    WHERE CONTAINS(index_url,'SYN(dui,a_thesaurus)', 0) > 0
    AND file_repository.file_id = file_security.file_id(+)
    AND file_security.auth_id = 0
    ORDER BY scr asc
    SCR FILE_ID FILE_TITLE
    0 74 Diplomatic Personnel
    0 81 DUI and PCA Offences
    0 136 Prisoners
    0 146 Rates
    0 168 Vehicle Collisions
    0 206 document4
    0 207 document5
    0 214 documentB
    0 240 Drug booklet
    8 64 Communications
    14 211 document5
    This is on Oracle 9i using Oracle Text.
    Thanks in advance

    To do this wouldn't you need to know the data in advance? The real source table had 1800 organisations and 8,000,000 transactions.
    I Tried this as well, creating a pl/sql package as follows.
    create or replace PACKAGE stack AS
    TYPE gnt_push_numbers IS TABLE OF NUMBER INDEX BY PLS_INTEGER;
    TYPE gvt_push_varchars IS TABLE OF VARCHAR(1000) INDEX BY PLS_INTEGER;
    gna_push_numbers gnt_push_numbers;
    gva_push_varchars gvt_push_varchars;
    FUNCTION PUSH ( pn_push_var NUMBER, pn_offset NUMBER) RETURN NUMBER DETERMINISTIC;
    FUNCTION PUSH ( pv_push_var VARCHAR, pn_offset NUMBER) RETURN VARCHAR DETERMINISTIC;
    FUNCTION POP_NUM ( pn_offset NUMBER) RETURN NUMBER DETERMINISTIC;
    FUNCTION POP_VAR ( pn_offset NUMBER) RETURN VARCHAR DETERMINISTIC;
    END stack;
    CREATE OR REPLACE
    PACKAGE BODY "STACK" AS
    FUNCTION push(pn_push_var NUMBER, pn_offset NUMBER) RETURN NUMBER deterministic IS
    BEGIN
    gna_push_numbers(pn_offset) := pn_push_var;
    RETURN pn_push_var;
    END push;
    FUNCTION push(pv_push_var VARCHAR, pn_offset NUMBER) RETURN VARCHAR deterministic IS
    BEGIN
    gva_push_varchars(pn_offset) := pv_push_var;
    RETURN pv_push_var;
    END push;
    FUNCTION pop_num(pn_offset NUMBER) RETURN NUMBER deterministic IS
    BEGIN
    RETURN gna_push_numbers(pn_offset);
    END pop_num;
    FUNCTION pop_var(pn_offset NUMBER) RETURN VARCHAR deterministic IS
    BEGIN
    RETURN gva_push_varchars(pn_offset);
    END pop_var;
    END stack;
    Unfortunately it appears to act before the rows are sorted, so will only work in specialised circumstances, in that you have to ensure the rows have been sorted before the function is used.
    SELECT PUSH(COL), POP..(COL)
    FROM ( SELECT etc.
    Luckily the client decided they didn't want to mix their graphs any more so a more classic approach using a base table select for actuals and then a date table select with a sub-query columns for the projection provided a simple solution.

  • The following query failed: GetUserProfileByName - with the wrong username

    I have 2 users (out of 800), who run into this issue on occasion. Their username is 'fccs\user1' in the profile db, and in every UserInfo table in the system. But when they try to go to certain sites or open an infopath form, this error gets thrown:
    The following query failed: GetUserProfileByName (User: FCCS\[email protected], Form Name: Template, IP: , Connection Target: , Request: http://fccsteams/sites/DataManagement/Tasks/Lists/Tasks/Folders1.aspx?RootFolder=/sites/DataManagement/Tasks/Lists/Tasks/2013/11&, Form ID: urn:schemas-microsoft-com:office:infopath:list:-AutoGen-2013-08-05T23:14:53:458Z Type: DataAdapterException, Exception Message: The remote server returned an error: (500) Internal Server Error.  Operation Failure ---> Access Denied: To create a user profile, you must be an administrator, or create your own profile and have personal features rights.  UnauthorizedAccessAccess Denied: To create a user profile, you must be an administrator, or create your own profile and have personal features rights. The remote server returned an error: (500) Internal Server Error.)
    Notice how the username is now the entire email address and not just the username. I have no idea why it thinks that that is their username. Any ideas?

    Hi,
    According to your post, my understanding is that you got query failed error.
    Melick had written a blog said that the form access the user profile web service (Userprofileservice.asmx) using  UDC
    file.
    You can check whether the UDC connection was still pointing to root site.
    You can change this file to match with the sub site collection. Otherwise there may be a cross domain access issue.
    There are similar threads for your reference.
    http://social.msdn.microsoft.com/Forums/sharepoint/en-US/9c2f7f4c-0fa9-43bd-94b1-1d7075e35841/5566-error-with-getuserprofilebyname-and-infopah-browser-forms-using-claims-based-authentication
    http://social.msdn.microsoft.com/Forums/en-US/49753330-40c0-4327-9a9b-2c3304a74e67/sharepoint-infopath-and-populating-forms-with-ad-data?forum=sharepointcustomizationlegacy
    Thanks & Regards,
    Jason 
    Jason Guo
    TechNet Community Support

Maybe you are looking for

  • Error in Asset Value carry forward to next year

    As a regular periodic process of Month/Year closing activities in SAP, Asset Year 2015 was opened and then closes the year 2014 and carried forward the Asset values to the year 2015. But unfortunately some of the Asset value had not been transferred

  • Can not Group text and shape/object

    I have previously made frequent use of grouping text and objects or images together. But in Keynote 4.0.2 this is not possible (for me at least). I am able to lock multiple images, but the group, mask and alpha buttons are not active when selecting a

  • Selecting custom colors in Microsoft Word

    I am really sorry if this is not the right place to ask this, but I can't find a better forum, and the official Microsoft newsgroup is lousy, so I'm hoping someone here will be able to help. I have a MacBook running OS X 10.4.10 and I use Office 2004

  • I cant see my stream photos on my pc

    HELLO. I HAVE IPHONE 4S IOS 5.1.1 I HAVE DOWNLODED ICLOUD CONTROL PANEL TO SEE MY PICS. IN MY SREAM PHOTOS ON MY MOBILE I HAVE ABOUT 350 BUT ON MY ICLOUD CONTROL PANEL I SEE ONLT 155. HOW CAN IT BE? THANKS RACHEL

  • Strange problem with JComboBox

    I am having a strange problem with JComboBox, I created a method as a JComboBox factory which returns a JComboBox filled with items. the method works fine and I can see the items in the JComboBox. The problem is when I try using the method myCombo.Se