outer join and OR condition

Hello world

I have a query that is not working properly. I'm trying to join two tables and I or condition and outer join
I get the error message
 ORA-01719: outer join operator (+) not allowed in operand of OR or IN

my query is as follow

SELECT l.* FROM table1 l, table2 map
WHERE (NVL(l.id, '-99') = NVL(map.id(+), NVL(l.id, '-99'))
        AND  l.TYPE = 'TKE')
      ) OR 
    (NVL(l.id, '-99') = NVL(map.id(+), NVL(l.id, '-99'))
AND NVL(l.type, '-99') = NVL(map.type(+), NVL(l.type, '-99'))
AND NVL(l.pos_22, '-99') = NVL(map.pos_22(+),NVL(l.pos_22, '-99'))
AND NVL(l.pos_27, '-99') = NVL(map.pos_27(+),NVL(l.pos_27, '-99'))
AND NVL(l.pos_17, '-99') = NVL(map.pos_17(+),NVL(l.pos_17, '-99'))
AND NVL(l.pos_18, '-99') = NVL(map.pos_18(+),NVL(l.pos_18, '-99'))
AND NVL(l.pos_12, '-99') = NVL(map.pos_12(+),NVL(l.pos_12, '-99'))
AND NVL(l.pos_16, '-99') = NVL(map.pos_16(+),NVL(l.pos_16, '-99'))
AND NVL(l.pos_34, '-99') = NVL(map.pos_34(+),NVL(l.pos_34, '-99'))
AND NVL(l.pos_43, '-99') = NVL(map.pos_43(+),NVL(l.pos_43, '-99'))
AND NVL(l.pos_14, '-99') = NVL(map.pos_14(+),NVL(l.pos_14, '-99'))
AND NVL(l.status_cd, '-99') = NVL(map.status(+),NVL(l.status_cd, '-99'))
AND NVL(l.action_cd,'-99') = NVL(map.action_cd(+), NVL(l.action_cd,'-99'))
AND NVL(l.sys,'-99') = NVL(map.sys(+), NVL(l.sys,'-99'))
AND NVL(l.ind,'-99') = NVL(map.ind(+), NVL(l.ind,'-99'))
  )
So, basically in the above query I say that if the type = "TKE" do not join on all columns of pos. If type is not TKE then do all the joints on all columns POS etc.
How do I rewrite query so that I can use OR and the outer JOIN in the same query?

Hello

It is one of several good reasons to use the ANSI join syntax. Move all the join conditions in the clause on, not the WHERE clause, and you do not use the sign +.

SELECT  l.*
FROM           table1 l
LEFT OUTER JOIN  table2 map  ON   (    NVL(l.id, '-99') = COALESCE (map.id, l.id, '-99')
                                    AND  l.TYPE = 'TKE'
                      )
                             OR  (     NVL (l.id, '-99') = COALESCE (map.id, l.id, '-99')
                          AND   NVL (l.type, '-99') = COALESCE (map.type), l.type, '-99')
                     ...

Instead of nesting the NVL statements, use COALESCE, as illustrated above. It is independent of the issue of the join.

Tags: Database

Similar Questions

  • BAD RESULTS WITH OUTER JOINS AND TABLES WITH A CHECK CONSTRAINT

    HII All,
    Could any such a me when we encounter this bug? Please help me with a simple example so that I can search for them in my PB.


    Bug:-8447623

    Bug / / Desc: BAD RESULTS WITH OUTER JOINS AND TABLES WITH a CHECK CONSTRAINT


    I ran the outer joins with check queries constraint 11G 11.1.0.7.0 and 10 g 2, but the result is the same. Need to know the scenario where I will face this bug of your experts and people who have already experienced this bug.


    Version: -.
    SQL> select * from v$version;
    
    BANNER
    --------------------------------------------------------------------------------
    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
    PL/SQL Release 11.1.0.7.0 - Production
    CORE    11.1.0.7.0      Production
    TNS for Solaris: Version 11.1.0.7.0 - Production
    NLSRTL Version 11.1.0.7.0 - Production

    Why do you not use the description of the bug test case in Metalink (we obviously can't post it here because it would violate the copyright of Metalink)? Your test case is not a candidate for the elimination of the join, so he did not have the bug.

    Have you really read the description of the bug in Metalink rather than just looking at the title of the bug? The bug itself is quite clear that a query plan that involves the elimination of the join is a necessary condition. The title of bug nothing will never tell the whole story.

    If you try to work through a few tens of thousands of bugs in 11.1.0.7, of which many are not published, trying to determine whether your application would be affected by the bug? Wouldn't be order of magnitude easier to upgrade the application to 11.1.0.7 in a test environment and test the application to see what, if anything, breaks? Understand that the vast majority of the problems that people experience during an upgrade are not the result of bugs - they are the result of changes in behaviour documented as changes in query plans. And among those who encounter bugs, a relatively large fraction of the new variety. Even if you have completed the Herculean task of verifying each bug on your code base, which would not significantly easier upgrade. In addition, at the time wherever you actually performed this analysis, Oracle reportedly released 3 or 4 new versions.

    And at this stage would be unwise to consider an upgrade to 11.2?

    Justin

  • Outer joins and null in the 'where' clause condition

    Hi people,

    Please help me on this.

    Here's my query.

    with x

    (select 'a' as a dual union all col1)

    Select 'b' as col1 of union double all the

    Select 'c' as double col1

    ),

    y as

    (

    Select 'b' as col2 from dual Union all the

    Select 'c' as col2 from dual Union all the

    Select would be "as col2 from dual Union all the"

    Select 'e' as col2 from dual

    )

    Select * x y right outer join

    on x.col1 = y.col2 and y.col2 is null

    Get all the lines of 'COL1' as null. Why like this?

    Just add the condition to the WHERE clause for example

    WITH x AS
    (SELECT 'a' AS col1 FROM dual UNION ALL
    SELECT 'b' AS col1 FROM dual UNION ALL
    SELECT 'c' AS col1 FROM dual
    ),
    y AS
    (
    SELECT 'b' AS col2 FROM dual UNION ALL
    SELECT 'c' AS col2 FROM dual UNION ALL
    SELECT 'd' AS col2 FROM dual UNION ALL
    SELECT 'e' AS col2 FROM dual
    )
    SELECT * FROM x LEFT OUTER JOIN y
    ON x.col1=y.col2                     ----want to add "and y.col2 is null " condition to get value "a"
    where y.col2 is null
    
  • Problem with Outer join and filter

    Hello

    I join two tables in the source using a left outer join. Outside of the join, I have a filter specified with condition TabA.C1 > TabB.C2.

    Now, when ODI generates the query it puts the left outer join on the filter condition as well. So he puts filter as

    where
    (1 = 1)
    And ((TabA.C1 = TabB.C1 (+)) AND)
    (TabA.C2 = TabB.C2 (+))
    And TabA.C10 > TabB.C14 (+)

    How to avoid this problem. I tried this performance on stage as well, always generated query remains the same.

    I use the incremental update of the IKM Oracle. My source and target are both on the same PB.


    ~ Chikk

    Hi Chikk,

    If you analyze the data, you'll see it's OK to have the "(+)" to the filter...

    Anyway, if you want to drop it, leave it as inner join and put the "(+)" manually to the join object.

    This help you?

  • left outer join and the where clause for the table to the right

    I want to join two tables a and b, where a is a must and b is a result set in option. When I use a left outer join to a to b, I want to achieve:

    1. Select a single column, two columns of b (not the join columns)
    2 - even if theres no friendly on the join column does not return data from one.
    3. If there is a match applies when the criteria on column b (table in option)

    so, how can I avoid no_data_found in this case? When I apply where criteria for b, so it does not return the data from one, which is a must.

    Sounds like a regular outer join to me...

    select a.col1, b.col2, b.col2
    from   tableA a
           left outer join tableB b
           on (a.id = b.id and b.colX = 'X')
    
  • Outer Join and joining several Tables

    Hello

    Oracle Database 10 g Express Edition Release 10.2.0.1.0 - product

    I have three tables AddProject, AssociateProjectLead, AddAssociate. Now I'm generating a report who will join AddProject and AssociateProjectLead for a list of all the projects, even if it doenst have a project coordinator. I used the outer join for this. However, if I want the name of the project leader, I need to search for AddAssociate table. By joining this table also, the outer join is no longer valid. Please see the result below

    CREATE TABLE  "ADDPROJECT" 
       (     "VERSIONNO" NUMBER(*,0), 
         "PROJID" VARCHAR2(20), 
         "PROJNAME" VARCHAR2(60), 
         "PROJSTARTDATE" DATE, 
         "PROJSTATUS" VARCHAR2(20), 
         "PROJENDDATE" DATE, 
         "PROJENDTYPE" VARCHAR2(20), 
         "PROJENDREASON" VARCHAR2(1000), 
         "UCPROJECTMANAGER" VARCHAR2(20), 
         "FROMDATE" DATE, 
         "TODATE" DATE, 
         "SRCHFIELD" VARCHAR2(20), 
         "OPERATOR" VARCHAR2(20), 
         "PARENTPROJID" VARCHAR2(20), 
         "PROJHIDDENDATE" VARCHAR2(20), 
          CONSTRAINT "PK_B36" PRIMARY KEY ("PROJID", "PROJHIDDENDATE") ENABLE
       )
    
    
    CREATE TABLE  "ADDASSOCIATE" 
       (     "VERSIONNO" NUMBER(*,0), 
         "ASSOCIATEID" NUMBER(9,0) NOT NULL ENABLE, 
         "ASSOCIATENAME" VARCHAR2(100) NOT NULL ENABLE, 
         "CTOJOINDATE" DATE, 
         "STATUS" VARCHAR2(20), 
         "ENDDATE" DATE, 
         "SRCHFIELD" VARCHAR2(20), 
         "OPERATOR" VARCHAR2(20), 
         "FROMDATE" DATE, 
         "TODATE" DATE, 
          CONSTRAINT "PK_B23" PRIMARY KEY ("ASSOCIATEID") ENABLE
       )
    
    CREATE TABLE  "ASSOCIATEPROJECTLEAD" 
       (     "VERSIONNO" NUMBER(*,0), 
         "PROJLEADASSOID" NUMBER(9,0), 
         "PROJID" VARCHAR2(20), 
         "ASSOCIATEID" NUMBER(9,0), 
         "PROJLEADSTARTDATE" DATE, 
         "STATUS" VARCHAR2(20), 
         "ASSOCPROJHIDDENDATE" VARCHAR2(20), 
         "PROJHIDDENDATE" VARCHAR2(20), 
         "ENDDATE" DATE, 
          CONSTRAINT "PK_B40" PRIMARY KEY ("ASSOCIATEID", "PROJID", "ASSOCPROJHIDDENDATE") ENABLE
       )
    
    
    elect ap.projid,apl.associateid
    from addproject ap, associateprojectlead apl
    where ap.projid = apl.projid(+)
    and ap.projhiddendate = apl.projhiddendate(+)
    
    
    PROJID ASSOCIATEID 
    Proj08 75825 
    Proj09 75825 
    Proj10 75825 
    Proj11 75825 
    Proj12 259811 
    Proj01 103035 
    Proj02 103035 
    Proj03 320092 
    Proj04 320092 
    Proj05 120974 
    Proj06 367393 
    Proj07 117618 
    Proj07 224882 
    Proj07 246652 
    prj001 -  
    prj001 -  
    
    16 rows returned in 0.00 seconds
    
    
    select ap.projid,apl.associateid,aa.associatename
    from addproject ap, associateprojectlead apl,addassociate aa
    where ap.projid = apl.projid(+)
    and ap.projhiddendate = apl.projhiddendate(+)
    and apl.associateid = aa.associateid
    
    
    PROJID ASSOCIATEID ASSOCIATENAME 
    Proj11 75825 Amarendra Kumar Singh 
    Proj10 75825 Amarendra Kumar Singh 
    Proj09 75825 Amarendra Kumar Singh 
    Proj08 75825 Amarendra Kumar Singh 
    Proj02 103035 Rajesh Jayaprakash 
    Proj01 103035 Rajesh Jayaprakash 
    Proj07 117618 Chetan Malhotra 
    Proj05 120974 Perumal Rajaram 
    Proj07 224882 Dilshad Ahmad 
    Proj07 246652 Shankar Kausley 
    Proj12 259811 Arunchandar Arun Vasan 
    Proj04 320092 Venkatesh Sarangan 
    Proj03 320092 Venkatesh Sarangan 
    Proj06 367393 Venkata Ramakrishna P 
    
    14 rows returned in 0.00 seconds
    How can I select all the values in table AddProject?

    Published by: Pramukh on August 23, 2012 12:18

    Hello

    I could get the result with a bit of modification

    select ap.projid,
           apl.associateid,
           aa.associatename
      from addproject ap
           left outer join
           associateprojectlead apl
        on ap.projid = apl.projid
       and ap.projhiddendate = apl.projhiddendate
           left outer join
           addassociate aa
        on apl.associateid = aa.associateid
    

    As a follow-up, I have a request more. In the report form, the user can select a particular project ID and the report should be generated as a result. For example;-he wants to see the results of the only "Proj08". I get the output as below, while the result should display only the details of 'Proj08 '.

    select ap.projid,
           apl.associateid,
           aa.associatename
      from addproject ap
           left outer join
           associateprojectlead apl
        on ap.projid = apl.projid
       and ap.projhiddendate = apl.projhiddendate
       and ap.projID = 'Proj08'
           left outer join
           addassociate aa
        on apl.associateid = aa.associateid
    ORDER BY ap.projID
    
    PROJID ASSOCIATEID ASSOCIATENAME
    Proj01 -  -
    Proj02 -  -
    Proj03 -  -
    Proj04 -  -
    Proj05 -  -
    Proj06 -  -
    Proj07 -  -
    Proj08 75825 Amarendra Kumar Singh
    Proj09 -  -
    Proj10 -  -
    Proj11 -  -
    Proj12 -  -
    prj001 -  -
    prj001 -  -  
    
  • outer join and LignesMax problem left

    I'm having a problem with the method and an sql join. My left table includes some documents that I want in the list, max 25 per page. These records have some notes are related in another table that is outer joined. When I specify the method in my cfoutput tag it includes my external joined table rows. So I could only go 5 records in my table left and 20 of my attachment table. What I want is 25 records in my table on the left and however the number of records in the table on the other that could be associated with these 25 records. Is this possible?

    I make two requests and avoid the outer join in this case:

  • Difference-conditions (join and a Where Clause)

    Hi people,

    I need to clearly agree on what a difference exactly when we put any condition in INNER JOIN and the WHERE Clause.

    I have tried both way and found the same results. Even in the statistics Plan not much differences.  Any help would be appreciated.

    As:

    1 here, I use filter store in the join condition - Inner

    "SELECT i., Gl * Sc1.Item I.

    Inner Join Sc1.Part P

    On P.Part_Id = I.Part_Id

    Inner Join Sc1.Location Gl

    On Gl.Location_Id = I.Location_Id

    And Gl.Location_Id in (1767, 1747,202,1625)

    Inner Join Sc1.Condition C

    On C.Condtion_Id = Gl.Condition_Id

    Where I.Inactive_Ind = 0

    And I.Condition_Id! = 325

    2. here I use filter store in Where clause-

    SELECT i., Gl * Sc1.Item I

    Inner Join Sc1.Part P

    On P.Part_Id = I.Part_Id

    Inner Join Sc1.Location Gl

    On Gl.Location_Id = I.Location_Id

    Inner Join Sc1.Condition C

    On C.Condtion_Id = Gl.Condition_Id

    Where I.Inactive_Ind = 0

    and I.LOCATION_ID in (1767, 1747,202,1625)

    And I.Condition_Id! = 325

    Thank you

    Mark



    Hello

    MarkCooper wrote:

    Hi guys,.

    To reply to all - I understand.

    1. its good practice to use conditions / filter (except CLAUSE) in the WHERE Clause rather Inner join? bon ?

    2. now, in my previous example. We could use the location code in where clause as it was in the two tables.

    What is the best practice to use the code to location here ( 1 /2) ?

    1. here I use filter store in the Inner join condition ( guess the location code is not in the article table)).

    "SELECT i., Gl * Sc1.Item I.

    Inner Join Sc1.Part P

    On P.Part_Id = I.Part_Id

    Inner Join Sc1.Location Gl

    On Gl.Location_Id = I.Location_Id

      And Gl.Location_Id in (1767, 1747,202,1625)

    Inner Join Sc1.Condition C

    On C.Condtion_Id = Gl.Condition_Id

    Where I.Inactive_Ind = 0

    And I.Condition_Id! = 325

    2. here I use filter store in Where clause (assume that the location code is not in the article table)-

    SELECT i., Gl * Sc1.Item I

    Inner Join Sc1.Part P

    On P.Part_Id = I.Part_Id

    Inner Join Sc1.Location Gl

    On Gl.Location_Id = I.Location_Id

    Inner Join Sc1.Condition C

    On C.Condtion_Id = Gl.Condition_Id

    Where I.Inactive_Ind = 0

      And Gl.Location_Id in (1767, 1747,202,1625)

    And I.Condition_Id! = 325

    Thank you

    If location_id isn't in the item table, then the join condition

    On Gl.Location_Id = I.Location_Id

    will cause an error.

    Once more, it should not affect results or performance if a condition like

    Gl.Location_Id in (1767, 1747,202,1625)

    is in the clause or the WHERE clause.  No matter if it is be a column called location_id in any other table, or if the same column Gl.Location_Id is used in other conditions.

    As this condition only refers to a table (GI), I recommend you put it in a WHERE clause, just to make the code clearer.

    Yet once, this applies only to the inner joins, not for outer joins and not to CONNECT BY queries.

  • Left Outer Join DR.

    Hi Experts,

    I have a requirement that says - see the chart for the past 10 days, regardless the presence data table in fact.
    Lets consider an example - Time_dim product, are my dimension tables, Purchase_Order is my fact table.

    I did it for external Purchase_Order in left RPD with TIME_DIM and inner join with the PRODUCT table.  and execution of query of exit-
    Select T.Date, P.item, count (distinct PO.order_no)
    TIME_DIM t, PRODUCT P, PURCHASE_ORDER PO
    where T.date_key = PO.date_key
    and P.item = in. agenda
    and P.item = 'laptop ';

    The query generated by OBIEE left outer join, but when the condition P.item = "Notebook" included in the query, and if there are no orders for this product in one of the date, that date will not come in the result set.

    the query to be generated by the OBIEE is-


    Select T.Date, PO.item, count (distinct PO.order_no)
    TIME_DIM t,.
    (SELECT P.ITEM, IN. ORDER_NO
    PRODUCT P, PO PURCHASE_ORDER
    WHERE P.item = in. agenda
    and P.item = 'Laptop') IN.
    WHERE T.date_key = PO.date_key (+);

    How to design the RPD to achieve this. All pray to advise on this. Thanks in advance.

    Thank you
    Chantal

    Hello

    You are on 11.1.1.7?

    I would say that your condition can be made without using external and maintenance of product and the standard between the FACT dimension, time inner join join.

    If you enable your property analysis OBIEE "Include Null values" will automatically return all the elements of time and product matching your filter (so you'll need to add a filter on 'Date' to limit it to the last 10 days or you will have a unique day of your time dimension).

    If you filter then on "Laptop", even if there is not a single value in order for "Laptop" in the last 10 days, he will be there on the screen.

    Easy, clean and you keep your inner join between the facts and Dimensions.

    Take a look at this example, I just did on SampleApp 406:

    Selection of 12 months (year 2010) and a customer (id = 89) and income. The model has only an inner join. I activate the option "Include Null values" and here is the result.

    A line with cells only empty because there is not a single revenue for customer 89 in 2010. This is exactly your condition.

    Honestly, do not touch your model using the outer join, you will have more side effects than benefits. Every single scan will do the outer join and you'll have a lot of data 'empty' return of the DB (more large data set containing just the null values) and probably you need the outer join in 15 to 25% of your analysis.

    Keep things simple, it will be faster and easier to maintain.

  • He had to know the right outer join using...

    He had to know the right outer join using...

    For example: first query left outer join for the emp table: SELECT EMPNO, ENAME, D.DEPTNO FROM EMP E, Department D WHERE the E.DEPTNO = D.DEPTNO)

    Second query left outer join for the Dept table: SELECT EMPNO, ENAME, D.DEPTNO FROM EMP E, Department D WHERE the D.DEPTNO = E.DEPTNO)

    In the example above I just Exchange where condition condition to get an outer join of two table with a left outer join itself. Wat is use right outer join, instead, I can swap the status of table name for the result. Please suggest...

    Hello

    chan001 wrote:

    He had to know the right outer join using...

    For example: first query left outer join for the emp table: SELECT EMPNO, ENAME, D.DEPTNO FROM EMP E, Department D WHERE the E.DEPTNO = D.DEPTNO)

    Second query left outer join for the Dept table: SELECT EMPNO, ENAME, D.DEPTNO FROM EMP E, Department D WHERE the D.DEPTNO = E.DEPTNO)

    In the example above I just Exchange where condition condition to get an outer join of two table with a left outer join itself. Wat is use right outer join, instead, I can swap the status of table name for the result. Please suggest...

    The two examples above use the old syntax outer join of Oracle. (I guess there should be a sign inside the parentheses, e.g.. +)

    ...  WHERE E.DEPTNO = D.DEPTNO (+)

    )

    The LEFT OUTER JOIN and RIGHT OUTER JOIN terms apply only to the ANSI join syntax, e. g.

    .

    .. FROM EMP E

    DEPT LEFT OUTER JOIN D ON E.DEPTNO = D.DEPTNO

    As Blushadow said above, there's no real point in having LEFT OUTER JOIN and RIGHT OUTER JOIN;  What you can do with one (or a combination of both) can be done with the other.  Most people use LEFT OUTER JOIN systematically and never use RIGHT OUTER JOIN.

    There are situations where using a combination of the two would mean a little less striking, but only a little less and this kind of situation is very common, and one may wonder if the somewhat shorter code is more specific.  I suggest that forget you RIGHT OUTER JOIN.

  • Right outer join

    There are four tables:

    Family
    Parent
    Child
    Grandchild

    Ideally, they have all documents, such as

    F1 - P1 - C1 - G1
    F2 - P2 - C2 - G2
    F3 - P3 - C3 - G3

    But sometimes,.

    F1 - P1 - C1 - null
    F2 - P2 - null - null
    F3 - P3 - null - null

    For the case of the latter, maybe I need to right outer join. If it's between two tables, the right outer join is easier. But among the four tables, inner family join parent, child of the outer join, then the big kid outer join. Maybe even this has been done? If an outer join in this case is not relevant, what other options are available?


    Thank you

    (ORACLE 11.2)

    Hello

    As Salomon, said

    FROM  p  LEFT  OUTER JOIN c
    

    means exactly the same thing that

    FROM  c  RIGHT OUTER JOIN p
    

    Everything you do with LEFT OUTER JOIN you could also do with RIGHT OUTER JOIN, and vice versa. If either one did not exist, you may do whatever you want with the other. In practice, it's just what's happening: most of the people always use LEFT OUTER JOIN and never use a RIGHT OUTER JOIN.

    You can have a series of outer joins cascading. If I understand your problem, a particular family may or may not have parents that belongs to him. If there are relatives, then you want to show the family with his parents to realteaed, but if there are no parents, so you want to show the family anyway. Similarly, you want to show parents whether or not they have children, and the children or not all my grandchildren are related to them. In general, which is written like this:

    ...
    FROM           family          f
    LEFT OUTER JOIN      parent          p    ON  p.family_id  = f.family_id
    LEFT OUTER JOIN      child          c    ON  c.parent_id  = p.parent_id
    LEFT OUTER JOIN      grandchild  g       ON  g.child_id   = c.child_id
    

    You can have a situation where (for example) a child is related to a family, but the child has no parent? In this case, you can still use LEFT OUTER JOIN, but join conditions would be different.

  • OUTER JOIN query returns the results of JOIN IN-HOUSE 11.2.0.1.0

    I'm data transfer in 11.2.01.0 (Windows XP 32-bit) and I wanted to compare the sizes of table with the same Table name in two different patterns, ML and SILENT, with a FULL OUTER JOIN (to account for all the tables and NULL values in a diagram).

    The scheme of ML has 176 tables: schema TUT a 133 tables. The use of a standard INNER JOIN gives 131 paintings.

    I get precisely the results with a FULL OUTER JOIN I get with an INTERNAL JOIN (not the same NULL values so I know they exist).

    This happens in SQL-Plus, SQL_Developer and using Oracle Wire pilot of Data_Direct.

    Here is the code:

    Login: SYS as SYSDBA or SYSTEM (same results for either)

    SELECT M.TABLE_NAME, M.NUM_ROWS, T.TABLE_NAME, T.NUM_ROWS
    OF SYS. ALL_TABLES M FULL OUTER JOIN SYS. ALL_TABLES T ON M.TABLE_NAME = T.TABLE_NAME
    WHERE
    M.OWNER = 'ML' AND
    T.OWNER = 'TUT';

    Produce the same results with LEFT OUTER joins and RIGHT OUTER joins in ASI and Oracle (+) syntax.

    Any thoughts?

    Hello

    If you read what I posted, forget it. MScallion (below) gave the correct answerr.

    If conditions such as

    owner   = 'ML'
    

    in the WHERE clause, and then they will reject the rows of the result set formed by the join condition.

    The inner join returns only 131 lines where the two 'paintings' have the same table_names.
    The outer joins return multiple lines (133, 176 or 178) before the place WHERE the provision is applied , but the WHERE clause eliminates all lines except the 131 found by the inner join.

    Published by: Frank Kulash, July 10, 2010 14:23

  • outer join: difference between two queries

    Below two queries which should give the same results in my opinion. I want that all records of u_protocol and the pval.u_protocol_variable_value value if necessary.

    Why the outer join in query2 does not work as in query1?


    Query1:
    select p.u_protocol_id, i.u_protocol_variable_value
    from lims_sys.u_protocol p,
    (
       select pval.u_protocol_id, pval.u_protocol_variable_value
       from lims_sys.u_protocol_variable pvar, lims_sys.u_protocol_value_user pval
       where pvar.u_protocol_variable_id = pval.u_protocol_variable_id
       and pvar.name = 'VALUE_Protocol_Group'
    ) i   
    where p.u_protocol_id  = i.u_protocol_id (+)
    Query2:
    select prt.u_protocol_id, pval.u_protocol_variable_value
    from lims_sys.u_protocol prt, lims_sys.u_protocol_variable pvar, lims_sys.u_protocol_value_user pval
    where pvar.u_protocol_variable_id = pval.u_protocol_variable_id
    and prt.u_protocol_id = pval.u_protocol_id (+)
    and pvar.name = 'VALUE_Protocol_Group'

    Hello

    When you perform an outer join, all conditions on the tables in option must be outer join conditions. Otherwise, the effect is an inner join.
    There is one exception: cascade of outer joins, external-junction b of a and c is outside attached to b. In this case, in the b - c join only columns of c are marked with the sign +.

    Re - write to obtain the same results as query1, query2 like this:

    select  prt.u_protocol_id
    ,      pval.u_protocol_variable_value
    from     lims_sys.u_protocol          prt
    ,      lims_sys.u_protocol_variable     pvar
    ,      lims_sys.u_protocol_value_user pval
    where     pvar.u_protocol_variable_id (+)     = pval.u_protocol_variable_id     -- cascading outer join
    and     prt.u_protocol_id           = pval.u_protocol_id (+)
    and     pvar.name (+)               = 'VALUE_Protocol_Group'     -- (+) added
    ;
    

    I find the syntax ANSI easier to use for all the joins and much easier for outer joins.

  • Outer join does not

    Hello

    Pls help me my request. I tried the following, but it does not give the expected results.

    Tab1
    EmplId, RepDt, Code, Hrs
    1/100,1/2009,199,8
    1/100,1/2009,200,4
    1/100,1/2009,255,3
    200,1/1/2009,200,4
    100.5/1/2009,199,8


    Tab2
    EmplId, RepDt, Code, Hrs
    1/100,1/2009,200,6
    200,1/1/2009,200,3

    I need output like this - 4 rows - need of all the rows from TAB1 when EMPLID, REPDT match TAB2, field values: need at a time when Code is also, when emlid, correspondence of the date, the Code missing so need A hrs, display ZERO as Tab2 hours.

    1/100,1/2009,199,8,0 - did not exist is not in tab2, so hrs Tab2 is ZERO
    1/100,1/2009,200,4,6 - Emplid, RepDt, Code match existence in Tab2, Tab1 Hrs 8, 6 Hrs Tab2
    1/100,1/2009,255,3,0 - did not exist is not in Tab2, so Tab2 hrs is equal to ZERO
    200,1/1/2009,200,4,3 - Emplid, Repdt, Code Match existed in Tab2, 4 Hrs of Tab1, Tab2 3 Hrs

    We are in 10g, Oracle.

    I tried the following
    T1. EmplId = T2.emplid AND T1.repdt = T2.repdt AND T1.code, T2.code = (+) - returns the unique corresponding lines, 2 rows.

    Pls help.

    Thanks in advance.

    Published by: NL 23 February 2009 09:20

    Hello

    See the Boneist first message in this thread:

    select t1.emplid, t1.repdt, t1.code, t1.hrs, nvl(t2.hrs, 0)
    from   tab1 t1,
           tab2 t2
    where  t1.emplid = t2.emplid (+)
    and    t1.repdt = t2.repdt (+)
    and    t1.code = t2.code (+)
    and    (t1.emplid, t1.repdt) in (select emplid, repdt
                                     from   tab2)
    order by repdt, emplid, code;
    

    As Boneist said, this fact corresponds to option (b)
    "(b) do just an outer join, with a condition EXISTS (or IN) in the WHERE clause to find corresponding repdts.
    The

    (+)
    

    an outer join are signs.

  • Create a view which limits a large table, but also allows an outer join?

    Oracle 10.2.0.4

    CREATE TABLE MY_PAY_ITEMS

    (EMP VARCHAR2 (8) NOT NULL)

    , PAY_PRD VARCHAR2 (8) NOT NULL

    , KEY1 VARCHAR2 (8) NOT NULL

    , KEY2 VARCHAR2 (8) NOT NULL

    , LN_ITEM VARCHAR2 (4) NOT NULL

    , ITEM_AMT NUMBER (24.2) NOT NULL

    VARCHAR2 (100) FILL NON-NULL)

    INSERT INTO MY_PAY_ITEMS

    SELECT A.EMP

    B.PAY_PRD

    C.KEY1

    D.KEY2

    E.LN_ITEM

    F.ITEM_AMT

    , '                      '

    FROM (SELECT TO_CHAR (ROWNUM, ' 00000000') 'EMP' FROM DUAL CONNECT BY LEVEL < = 50) has

    , (SELECT '2010-' |) To_char(rowNum,'00') 'PAY_PRD' FROM DUAL CONNECT BY LEVEL < = 52) B

    , (SELECT TO_CHAR (ROWNUM, ' 000') 'KEY1' FROM DUAL CONNECT BY LEVEL < = 8) C

    , (SELECT TO_CHAR (ROWNUM, ' 000') 'Key2' FROM DUAL CONNECT BY LEVEL < = 5) D

    , (SELECT TO_CHAR(ROWNUM,'000') 'LN_ITEM' FROM DUAL CONNECT BY LEVEL < = 20) E

    (round (DBMS_RANDOM. VALUE * 400.2) "ITEM_AMT" of the double) F

    CREATE A UNIQUE INDEX MY_PAY_ITEMS ON MY_PAY_ITEMS (MEP, PAY_PRD, KEY1, KEY2, LN_ITEM)

    CREATE TABLE MY_ITEM_DISPLAY

    (THE VARCHAR2 (4) OF DISPLAY_CODE NOT NULL)

    , NUMBER (2) SEQUENCE NON-NULL

    , COLUMN_ITEM1 VARCHAR2 (4) not null

    , COLUMN_ITEM2 VARCHAR2 (4) not null

    , COLUMN_ITEM3 VARCHAR2 (4) not null

    COLUMN_ITEM4 VARCHAR2 (4) not null)

    INSERT INTO MY_ITEM_DISPLAY VALUES ('01 ', 10, '001', '003', '004',' 005');

    INSERT INTO MY_ITEM_DISPLAY VALUES ('01 ', 20 '007', '013', '004',' 009');

    INSERT INTO MY_ITEM_DISPLAY VALUES ('01', 30 ' 001', '004', '009',' 011');

    INSERT INTO MY_ITEM_DISPLAY VALUES ('01', 40, '801 ', ' 304 ', 209',' 111');

    INSERT INTO MY_ITEM_DISPLAY VALUES ('02 ', 10, '001', '003', '004',' 005');

    INSERT INTO MY_ITEM_DISPLAY VALUES ('02 ', 20 '007', '013', '004',' 009');

    INSERT INTO MY_ITEM_DISPLAY VALUES ('02', 30 ' 001', '004', '009',' 011');

    MY_PAY_ITEMS is a table that stores line of payslip items.  It has a total area of 500,000,000 lines.

    PEM is the unique id, we have about 200,000 employees (with about 50,000 being active today).

    PAY_PRD is a weekly pointer (2010-01, 2010-02, 2010-52), we have the 2004 data and add a new pay period each week.  2010 01 is defined as the first Monday in 2010 for the first Sunday in 2010, etc.

    Key1 is an internal key, it follows the chronology in the pay period.

    KEY2 is a child of KEY1, there follows the sequence of events in KEY1.

    LN_ITEM is the component of actual compensation resulting from the event, on average, a person produces 20 lines per event.  Note that in this example, everyone gets the same LN_ITEM values, but in practice it is selected 20 of 300

    ITEM_AMT is the net salary per command line.

    FILLING is a set of fields that are unrelated to this issue, but act as a brake on the charges of the line.

    MY_ITEM_DISPLAY is an array that describes how some screens should display items.  The screen itself is a grid of 4 poles, with the content of each cell is defined as a LN_ITEMS search to retrieve the relevant LN_AMT.

    We have an application that receives a DISPLAY_CODE and an EMP.  It automatically creates an sql statement in the sense of

    SELECT * FROM MY_VIEW WHERE DISPLAY_CODE =: 1 AND EMP =: 2

    and returns the output to the user.

    My challenge is that I need to rewrite MY_VIEW as follows:

    (1) (select the relevant lines from MY_ITEM_DISPLAY where DISPLAY_CODE =: 1)

    (2) select the relevant all MY_PAY_ITEMS lines that meet the criteria

    (a) EMP =: 2

    (b) PAY_PRD = (a more recent for EMP and sysdate, so if he got last paid 2010-04, return 2010-04)

    (c) KEY1 = (highest key1 in EMP and PAY_PRD)

    (d) KEY2 = (highest key2 in KEY1, PAY_PRD and EMP)

    (3) I then need to cross reference to create tabular output

    (4) Finally, I have to return a 0 line where there is no LN_ITEMs (DISPLAY_CODE 01, 40 sequence contains possible values for this scenario)

    The following query is part of it (but not the PAY_PRD, KEY1, KEy2)

    Select * from)

    SELECT A.DISPLAY_CODE

    B.EMP

    A.SEQUENCE

    , MAX (DECODE (B.LN_ITEM, A.COLUMN_ITEM1, B.ITEM_AMT, 0)) 'COL1 '.

    , MAX (DECODE (B.LN_ITEM, A.COLUMN_ITEM2, B.ITEM_AMT, 0)) 'COL2 '.

    , MAX (DECODE (B.LN_ITEM, A.COLUMN_ITEM3, B.ITEM_AMT, 0)) 'COL3 '.

    , MAX (DECODE (B.LN_ITEM, A.COLUMN_ITEM4, B.ITEM_AMT, 0)) 'COL4 '.

    OF MY_ITEM_DISPLAY A, MY_PAY_ITEMS B

    WHERE B.PAY_PRD = ' 2010-03'

    GROUP OF A.DISPLAY_CODE, B.EMP, A.SEQUENCE)

    WHERE DISPLAY_CODE = '01'

    AND EMP = '0000011'

    SEQUENCE ORDER

    My questions

    (1) how I do PAY_PRD, KEY1, KEY2 forced, can I use a form any of ROW_NUMBER() FUNCTION?

    (2) how can I deal with the fact that none of the 4 LN_ITEMS column can exist (see sequence 40, none of these can exist)...  Ideally the SQL above should return

    01, 0000011, 10, < a digit - > < number > - < a digit - > < some number >

    01, 0000011, 20, < a digit - > < number > - < a digit - > < some number >

    01, 0000011, 30, < a number--> < number > - < number > - < number > -

    01, 0000011, 40, 0, 0, 0, 0

    I tried a UNION, but it prevented the view to eliminate most of the MY_PAY_ITEMS lines, because it solves ALL MY_PAY_ITEMS instead of simply retrieve lines for the EMP passed to the view.  The same seems to be true for outer joins.

    Hi Paula,

    It does not handle SEQNUM 40, it's just that your second set of test data did not SEQNUM 40. When I put in the first set of values MY_ITEM_DISPLAY, I get:

    DISP EMP SEQUENCE COL1 COL2 COL3 COL4

    ---- -------- ---------- ---------- ---------- ---------- ----------

    01 00000011 10 101.1 103.1 105.1 104.1

    01 00000011 20 107.1 113.1 104.1 109,1

    01 00000011 30 101.1 104.1 109.1 99.99

    01 00000011 40 0 0 0 0

    If this isn't the issue, you will need to explain the requirement of "outer join" and what you want more. Apart from his return nothing if there is absolutely no element of remuneration of the employee, this query will always return a line for each line MY_ITEM_DISPLAY for the display_code. If there is absolutely no data, no return line seems reasonable.

Maybe you are looking for

  • Firefox crashes unexpectedly

    My Firefox crashes unexpectedly within seconds using the internet. I use the latest version, I run my program of protection anti-virus, installed the Mircosoft Security Scanner, I updated my plugins, I installed the "Malwarebytes' Anti-Malware" provi

  • smoethings happened to my pen!

    To cut a long story short, I can't write properly because my pen registers before touching the screen (a few millimetres above). This means that it does not recognize my lifting pen actually go to the page and everything meets everything simply. I th

  • What is error C00D1197 in windows media player when you try to burn a CD.?

    What is error C00D1197 in windows media player when you try to burn a CD.?

  • KB972270 Win 7, error 80070643

    Hello I recently discovered that my laptop is not updated properly, such as windows update is still stuck at KB972270, giving the error 80070643. I run win 7 and I do not have office 2003, which seems related to the error, the patch is reclassificati

  • Windows live mail will not start.

    This problem started a week ago. The screen just hangs but I see the new mail icon in the taskbar. Then I have to go into the Task Manager and delete the exe command to stop it. I tried uninstalling and reinstalling, various 'solutions' suggested on