Apply filter before Left Outer joins in OBIEE.

Hi Experts,
I have an user requirement where a filter need to be applied before the Left outer join applied on the OBIEE generated query.
But obiee normally applies the filters on the resulted data after the Left outer join applied which eliminates some required data.
Is there any way to achieve this at the RPD level.
Thanks
Swami

Swam,
your syntax for sql is not correct.
you are doing outer join and filter I am not sure what you are trying to achieve here
assume T1 is fact table and T2 is time dimension
T1 left outer T2 means you are trying to pull all the records from fact irrespective of the date filter!!
you will see all the records.
Please manually write the Sql and we have lot of ways  to force that in to OBIEE.
Thanks
NK

Similar Messages

  • Left Outer Join In OBIEE

    Hi,
    I have two Oracle tables in the physical layer: a fact table and a dimension table.
    The fact table (FACT_TBL) like this:
    CURR_MTH | PREV_MTH | CURR_GRADE | PREV_GRADE | CITY | VALUE
    Jun | May | B | A | X | 5
    Jun | May | A | A | Y | 10
    Jun | May | C | C | X | 15
    Jun | May | D | C | Y | 20
    And the dimension table (GRADE_TBL) like this:
    GRADE | GRADE_NAME
    A | A
    B | B
    C | C
    D | D
    I joined those two tables above in the physical layer using GRADE field. Then, I created a business model using those two tables. I want to create a 4x4 matrix report with PREV_GRADE as the first column and the CURR_GRADE accross to the right like this:
    CURR_MONTH PROMPT = Jun
    PREV_MONTH PROMPT = May
    CITY PROMPT = X
    PREV_GRADE | A | B | C | D |
    A | (null) | 5 | (null) | (null) |
    B | (null) | (null) | (null) | (null) |
    C | (null) | (null) | 15 | (null) |
    D | (null) | (null) | (null) | (null)|
    The problem is that I couldn't show all grade (A to D) in the PREV_GRADE column in that table. Every time I filter the CITY in the prompt to X, I always get only A and C. The B and D rows are suppressed. How do I achieve the left outer join that I wanted above? Thanks a lot for the help.

    hi,
    this can be done in BMM layer.
    select the required BMM model. Right click and select "Buisness Model Diagram" and "whole diagram" .
    now double click on the joining link and specify the type of join here. (assuming you have used "New Complex join" to join these tables).

  • Filter on "---" in Left Outer Join Query

    Hi guys,
    very basic question but I have not found an answer, yet. I built an left outer join MDO query and need to select all those dataset that did not find a "partner", that is fields are set to "---". However, I do not manage to filter on '---', NULL...
    When using SQL, it appears to be a String "---" but in MDO???

    Hey guys, found out that IS NULL needs to be used in query. Anyway, it appears to cause problems somewhere else.
    I placed an IS NULL filter expression inside a join query but query did not return any results when called in by transaction. After removing this line, both NULL and NOT NULL data were returned. When used in test mode, IS NULL was working fine...

  • Left outer join usage in obiee BMM layer

    Hi All,
    We lately started using left outer join in our bmm layer , to meet the requirement expectation .
    problem : We have two tables  Fact A , Dim B . There is an join int_id column to join them . Problem is... in table Dim B , we have 3 millions rows of Int_id and in fact table it is loaded for only data available(1 million rows).
    Due to this we are dropping rows  in the report ..as it is only getting data where fact.int_id = dim.int_id. So we used left outer join to solve to one particular report .(we know we can do ETl to load dummy int_id and make it null , but it is huge effort ..so we did left outer join)
    These days , same kind of reports are in requirement . if i keep on doing same left outer join to meet the requirement in BMM layer ? is there any disadvantages due to this ? any performance degrade due to this ? please throw few lines on left outer join and its usage ?
    Thanks,
    Sri

    Remodel your tables that might be a partition or any other way and follow in BI as per your new model.
    Simply: Go for ETL kind of solution

  • Display all dates between date range (Time Dimension left outer join Fact)

    All,
    I have done some searching around this issue but within all the posts regarding date variables, date prompts and date filtering I haven't seen one exactly answering my issue (maybe they are and I just dont have my head around it correctly yet).
    My report requirement is to allow a user to select a start day and an end day. The report should show all activity between those two days - AND display 0/null on days where there is no activity. That second part is where I am getting hung up.
    The tables in question are:
    TimeDim
    EventFact
    CustomerDim
    My BMM is setup as follows:
    TimeDim left outer join EventFact
    CustomerDim inner join EventFact
    If I run a report selecting DAY from TimeDim and a measure1 from EventFact with day range 1/1/2010 - 12/31/2010 .. I get a record for every day and it looks perfect because of the left outer join between TimeDim and CustomerDim.
    But .. if I add in a field from CustomerDim, select TimeDim.DAY, CustomerDim.CUSTNAME, EventFact.MEASURE1, OBIEE only returns records for the days that have EventFact records.
    This is due to the fact that the TimeDim is still outer joined into EventFact but adding in CustomerDim makes OBIEE setup an inner join between those tables which then causes only data to be returned where EventFact data exists.
    There is a way around this in this simple case and that is to define the relationship between CustomerDim and EventFact as an outer join as well. This will give the desired effect (but an outer join between these two tables is not the true relationship) and as I add additional dimensions and add additional logical sources to a single dimension in the BMM it gets complicated and messy.
    Ive also messed with setting the driving table in the relationship, etc.. but it has not given the desired effect.
    Has anyone ever encountered the need to force display all dates within a specfied range with a fact table that may not have an entry for every date?
    Thanks in advance.
    K
    Edited by: user_K on Apr 27, 2010 11:32 AM

    It worked!!!* Even my time drill downs and date based filtering still work!
    That is awesome. Never would have thought of that intuitively.
    Now, just need a little help understanding how it works. When I run my report and check the logs I can see that two queries are issued:
    Query 1: Joins the fact table to all the associated dimensions. I even changed all the relationships to inner joins (which is what they truly are). And calculates the original measure. If I copy and paste this query into sql developer it runs fine but only returns those rows that joined to the time dimension - which is what was happening before. It is correct but I wanted a record for every time dimension record.
    Query 2: Looks like the following:
    select sum(0)
    from timedim
    where date between <dateprompt1> and <dateprompt2>
    group by month *<--* this is the time dimension level specified in Query 1, so it knows to aggregate to the month level as was done in query 1
    Final Question: So what is OBIEE doing ultimately, does it issue these two requests and then perform a full outer join or something to bring them together? I couldn't see anywhere in the log a complete query that I could just run to see a similar result that I was getting in Answers.
    Thanks for all the help .. Id give more points if I could.
    K

  • Sql help (left outer join)

    Hi All,
    I am referring 2 regular tables from the HR schema which you get when you install Oracle 9i , Now the issue is that I want all the rows from my employees table even if the row doesnt have the salary equal to 2500.
    Here is my Sql:
    select e.employee_id
         , e.first_name
         , e.last_name
         , e.salary
         , e.department_id e_dep_id
         , d.department_id d_dep_id
         , d.department_name
         , d.location_id
    from employees e
    , departments d
    where 1 = 1
         And e.department_id = d.department_id(+) And e.SALARY = 2500
    I am achieving my result set from the below query though(its just a syntactical problem) , please help :
    select e.employee_id
         , e.first_name
         , e.last_name
         , e.salary
         , e.department_id e_dep_id
         , d.department_id d_dep_id
         , d.department_name
         , d.location_id
    from employees e left outer join
    departments d
    on e.department_id = d.department_id And e.SALARY = 2500
    Regards
    Rahul

    Mac_Freak_Rahul wrote:
    Well my requirement is to pull all the records from my driving table(ie employees) doesnt matter weather the condition satisfies or not. Just to add to that lets say I would need to bring another table and my join criteria involves data from the employees table and the third table(in this case I need to make sure that all the rows from my driving table remains and doesnt get filter out). Please help my only problem is of the new syntax of outer joins.
    Regards
    RahulRahul,
    Why do you want to use "oracle only syntax ( + )"? I highly recommend you to use ANSI syntax, it's much more readable:
    This is from Oracle's documents:
    Oracle recommends that you use the FROM clause OUTER JOIN syntax rather than the Oracle join operator. Outer join queries that use the Oracle join operator (+) are subject to the following > rules and restrictions, which do not apply to the FROM clause OUTER JOIN syntax:
    You cannot specify the (+) operator in a query block that also contains FROM clause join syntax.
    The (+) operator can appear only in the WHERE clause or, in the context of left-correlation (that is, when specifying the TABLE clause) in the FROM clause, and can be applied only to a column > of a table or view.
    If A and B are joined by multiple join conditions, then you must use the (+) operator in all of these conditions. If you do not, then Oracle Database will return only the rows resulting from a > simple join, but without a warning or error to advise you that you do not have the results of an outer join.
    The (+) operator does not produce an outer join if you specify one table in the outer query and the other table in an inner query.
    You cannot use the (+) operator to outer-join a table to itself, although self joins are valid. For example, the following statement is not valid:
    -- The following statement is not valid:
    SELECT employee_id, manager_id
    FROM employees
    WHERE employees.manager_id(+) = employees.employee_id;
    However, the following self join is valid:
    SELECT e1.employee_id, e1.manager_id, e2.employee_id
    FROM employees e1, employees e2
    WHERE e1.manager_id(+) = e2.employee_id;
    The (+) operator can be applied only to a column, not to an arbitrary expression. However, an arbitrary expression can contain one or more columns marked with the (+) operator.
    A WHERE condition containing the (+) operator cannot be combined with another condition using the OR logical operator.
    A WHERE condition cannot use the IN comparison condition to compare a column marked with the (+) operator with an expression.
    A WHERE condition cannot compare any column marked with the (+) operator with a subquery.Best Regards,
    Gokhan
    If this question is answered, please mark appropriate posts as correct/helpful and the thread as closed. Thanks

  • 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

  • Tuning a left outer join

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

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

  • Left Outer Join 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

  • 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 left outer join in one-one mapping

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

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

  • Left outer join functions like simple join

    I created two views SCO_REQGROSSLINES_V & SCO_REQLINESCOMPLETE on Oracle requisitions base tables. Our business rules enforce the following identity: the number of gross requisition lines will always be greater than or equal to the number of requisition lines complete. (By complete I mean delivered.)
    Each view has a key named DATESUBINV_KEY constructed of a transaction date and the subinventory code using this logic:
    , TO_CHAR(TRUNC(transaction_date),'YYYYMMDD') || subinventory_code
    On 03-SEP-2010 a user created a requisition with one line item for material from the HEAT subinventory which was not delivered. This row is retuned in the result set when I query on SCO_REQGROSSLINES_V but is NOT returned when I query on SCO_REQLINESCOMPLETE. So far so good.
    When I issue either of the the following left outer joins I do not get the row for the row for the HEAT subinventory on 03-SEP-2010:
    select rgl.trxn_date
    , rgl.subinventory
    , rgl.line_count gross_line_count
    , rgl.ext_prc gross_value
    , rlc.line_count lines_filled
    , rlc.ext_prc lines_filled_value
    from SCO_REQGROSSLINES_V rgl left outer join sco_reqlinescomplete_v rlc
    ON rgl.datesubinv_key = rlc.datesubinv_key
    where rgl.TRXN_DATE BETWEEN to_date('29-AUG-2010') AND to_date('04-SEP-2010')
    and rlc.trxn_date BETWEEN to_date('29-AUG-2010') AND to_date('04-SEP-2010')
    order by rgl.trxn_date, rgl.subinventory
    select rgl.trxn_date, rgl.subinventory
    , rgl.line_count gross_line_count
    , rgl.ext_prc gross_value
    , rlc.line_count lines_filled
    , rlc.ext_prc lines_filled_value
    from SCO_REQGROSSLINES_V rgl
    , sco_reqlinescomplete_v rlc
    where rgl.TRXN_DATE BETWEEN to_date('29-AUG-2010') AND to_date('04-SEP-2010')
    and rlc.trxn_date BETWEEN to_date('29-AUG-2010') AND to_date('04-SEP-2010')
    AND rgl.datesubinv_key = rlc.datesubinv_key(+)
    order by rgl.trxn_date, rgl.subinventory
    Question: Why would the left outer joins function as a simple join on DATESUBINV_KEY? Do keys on views function differently than keys defined in the data dictionary? If they do how can I make these keys to function like data dictionary keys?

    Hi,
    The WHERE clause is applied after the outer join is completed. In your example, rows from rgl will be in the result set even if they have no match in rlc. In those cases, all the columns from rlc will be NULL.
    Okay, so you have these rows that contain data from rgl but NULLs where the data from rlc was supposed to go. Now it's time to start the WHERE clause. You then apply conditions like this in the WHERE clause:
    AND     rlc.trxn_date BETWEEN ...NULL is between anything, so the row that the outer join prodeuced is rejected.
    All conditions involivn columns from rlc probably need to be part of the join condition, not the WHERE clause.
    For example, in you first query the FROM and WHERE clauses might be:
    FROM          sco_reqgrosslines_v      rgl
    LEFT OUTER JOIN  sco_reqlinescomplete_v  rlc  ON    rgl.datesubinv_key   = rlc.datesubinv_key
                                            AND   rlc.trxn_date       BETWEEN TO_DATE ( '29-AUG-2010'
                                                                        , 'DD-MON-YYYY'
                                                  AND       TO_DATE ( '04-SEP-2010'
                                                              , 'DD-MON-YYYY'
    WHERE   rgl.trxn_date     BETWEEN TO_DATE ( '29-AUG-2010'
                             , 'DD-MON-YYYY'
                   AND     TO_DATE ( '04-SEP-2010'
                             , 'DD-MON-YYYY'
                             )Always use (at least) two arguments when calling TO_DATE.
    Conditions that only involve rgl can be in the WHERE clause, but if any conditions from rlc are in the WHERE clause, then the effect will be the same as an inner join.
    There no difference between tables and views (or sub-queries) in this regard: the same thing would happen regardless of whether rgl and rlc were really tables or not.

  • Left Outer Join

    I have tables with index on it , i join them using left outer join. So the table access path choosen by the optimizer is full table access.
    index not used in it. is there any other way to use index ? alternate to left outer join to use index ?
    thanks
    Raj

    Hi
    I have tables with index on it , i join them using left outer join. So the table access path choosen by the optimizer is full table access.
    index not used in it. is there any other way to use index ? alternate to left outer join to use index ?There are several ways, for this problem
    1. May be your tables does't have statistics..do analyse tables.
    2. Joining conditions are wrong.
    3. Check Filter conditions.
    KPR

  • Left outer join using anyOfAllowingNone

    Hi,
    I'm trying to join two tables (tableA and tableB) with left outer join using anyOfAllowingNone (One to many relationship) and try to fetch the tableB data with some constraint on it.
    But the sql generated out of the expression builder is not a proper left join, it actually forms a inner join, which brings only table A data which satisfies all the condition. Actually I want all of tableA data and for every record from tableA I want the data from TableB which matches the key from tableA to tableB and some condition applied on tableB data.
    I guess I'm doing some thing wrong, I went through the document and sample but still its not getting me the right data.
    Below is my expression builder:
    exp = builder.get("tableA_K").equal(some value);
    exp = exp.and(builder.get("effectiveIn").toChar("MM/dd/yyyy").lessThanEqual(date));
    exp = exp.and(builder.get("effectiveOut").toChar("MM/dd/yyyy").greaterThanEqual(date));
    exp1 = builder.anyOfAllowingNone("tableBCollectionAttribute").get("effectiveIn").toChar("MM/dd/yyyy").lessThanEqual(date);
    exp1 = exp1.and(builder.anyOfAllowingNone("tableBCollectionAttribute").get("effectiveOut").toChar("MM/dd/yyyy").greaterThanEqual(date));
    return exp.and(exp1);
    Below is the sample query generated:
    select distinct tableA.all data
    where (((((tableA.key = 2219785)
    and (to_char(tableA.EFFECTIVE_IN_S, 'MM/dd/yyyy') <= '03/27/2008'))
    and (to_char(tableA.EFFECTIVE_OUT_S, 'MM/dd/yyyy') >= '03/27/2008'))
    and ((to_char(tableB.EFFECTIVE_IN_S, 'MM/dd/yyyy') <= '03/27/2008')
    and (to_char(tableB.EFFECTIVE_OUT_S, 'MM/dd/yyyy') >= '03/27/2008')))
    and (tableB.key (+) = tableA.tableB_Key))
    Any help is appreciated. Thanks
    Sai.

    hi Mansi,
    this is how i populate
    SELECT VGBEL LFIMG POSNR VBELN FROM LIPS INTO  TABLE IT_delv  FOR ALL ENTRIES IN IT_VBAP WHERE VGBEL = IT_VBAP-VBELN.
    LOOP AT IT_delv INTO WA_delv.
    WA_FINAL-VBELN_1 = WA_DELV-VBELN_1.
    WA_FINAL-LFDAT =   WA_DELV-LFDAT.
    WA_FINAL-LFIMG   = WA_DELV-LFIMG.
    WA_FINAL-POSNR2 =   WA_DELV-POSNR2..
    APPEND WA_FINAL TO IT_FINAL.
    CLEAR: WA_FINAL , WA_delv.
    ENDLOOP.
    LOOP AT IT_FINAL INTO WA_FINAL.
    READ TABLE IT_vbap INTO WA_vbap WITH KEY VGBEL = WA_FINAL-VBELN.
      WA_FINAL-VBELN = WA_VBAP-VBELN.
    WA_FINAL-MATNR = WA_VBAP-MATNR.
    WA_FINAL-KWMENG = WA_VBAP-KWMENG.
    WA_FINAL-NETWR = WA_VBAP-NETWR.
    MODIFY IT_FINAL FROM WA_FINAL.
    ENDLOOP.
    My question is , it_vbap has 5 five records A,B,C,D,E.
    in it_delv ,there are 20 record corrresponding to A,B,D of IT_VBAP.
    in final table i wont get info of recors B,E. I want those info also in final table ..how can i do that...

  • 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

Maybe you are looking for