Query of query with left outer join

Hi,
I cannot use joins in query of query, I try the old method using the ( + ) but no luck "Query Of Queries syntax error. Encountered ( + )."
Here is an example of my query code:
select p.part_id, s.supplier_name, s.second_name
from part p, supplier s
where p.supplier_id = s.supplier_id ( + )
and  p.second_id = s.second_id ( + );
PART SUPPLIER_NAME  SECOND_NAME
P1   Supplier#1     A
P2   Supplier#2
P3
P4
How can I do the same in query of query syntax?
Thanks!

I found a solution:
http://www.bealearts.co.uk/blog/2007/06/20/how-to-do-an-outer-join-in-query-of-queries/
I am not sure about my second condition. i create the join query for the empty columns.
select part.part_id, supplier.supplier_name, supplier.second_name
from part, supplier
where part.supplier_id = supplier.supplier_id
and  supplier.second_id is null
union
select part.part_id, supplier.supplier_name, supplier.second_name
from part, supplier
where part.supplier_id = supplier.supplier_id
and  part.second_id = supplier.second_id
union
select part.part_id, joinQuery.supplier_name, joinQuery.second_name
from part, joinQuery
where part.supplier_id not in (#ValueList(supplier.supplier_id)#)
Can anyone check and let me know if this is correct?
My final result have one less row from parts table.
Thanks

Similar Messages

  • Update Statement with left outer join

    hi,
    i have to update a column in table "a" from table "b" and both of them joined with left outer join
    How can I do this
    Thanks in Advance

    Please consider the following when you post a question. This would help us help you better
    1. New features keep coming in every oracle version so please provide Your Oracle DB Version to get the best possible answer.
    You can use the following query and do a copy past of the output.
    select * from v$version 2. This forum has a very good Search Feature. Please use that before posting your question. Because for most of the questions
    that are asked the answer is already there.
    3. We dont know your DB structure or How your Data is. So you need to let us know. The best way would be to give some sample data like this.
    I have the following table called sales
    with sales
    as
          select 1 sales_id, 1 prod_id, 1001 inv_num, 120 qty from dual
          union all
          select 2 sales_id, 1 prod_id, 1002 inv_num, 25 qty from dual
    select *
      from sales 4. Rather than telling what you want in words its more easier when you give your expected output.
    For example in the above sales table, I want to know the total quantity and number of invoice for each product.
    The output should look like this
    Prod_id   sum_qty   count_inv
    1         145       2 5. When ever you get an error message post the entire error message. With the Error Number, The message and the Line number.
    6. Next thing is a very important thing to remember. Please post only well formatted code. Unformatted code is very hard to read.
    Your code format gets lost when you post it in the Oracle Forum. So in order to preserve it you need to
    use the {noformat}{noformat} tags.
    The usage of the tag is like this.
    <place your code here>\
    7. If you are posting a *Performance Related Question*. Please read
       {thread:id=501834} and {thread:id=863295}.
       Following those guide will be very helpful.
    8. Please keep in mind that this is a public forum. Here No question is URGENT.
       So use of words like *URGENT* or *ASAP* (As Soon As Possible) are considered to be rude.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • 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

  • Trouble With Left Outer Join

    I'm kind of new to using left outer joins, so I don't know if I'm doing it quite right. Right now there's only one table that may or may not have a corresponding record, so I'm only using left outer join on it. I get the error ORA-00904: "A"."SGBSTDN_PIDM": invalid identifier right now when I try to run my query. This gives me the impression that I need to use left outer join on all the tables in my FROM clause. Any suggestions on what I need to do?
    /*Get those students not awarded ACG1 yet with an entry in shrlgpa*/
    SELECT spriden_id id, spriden_last_name||', '||spriden_first_name name, sgbstdn_styp_code student_type,
    sorhsch_graduation_date hsch_grad_date,shrlgpa_hours_earned hours_earned,rorenrl_finaid_adj_hr hours_enrolled,
    0 AS disbursement_to_date, 0 AS offer_amt, 0 AS current_disbursement,
    rnvand0_unmet_need unmet_need, 'N' AS awarded
    FROM RCRESAR,RCRAPP1,SORHSCH,RORHSDT,SGBSTDN A,SORLCUR, shrlgpa, rorstat, ROBINST, spriden
    ,rnvand0
    LEFT OUTER JOIN rorenrl ON (A.sgbstdn_pidm = rorenrl_pidm)
    WHERE (RCRESAR_PELL_ELGBL = 'Y')
        AND  SORHSCH_GRADUATION_DATE>'01-JAN-2006'
        AND  RCRAPP1_CITZ_IND IN ('1','2')
        AND  RCRAPP1_CURR_REC_IND='Y'
        /*Possible change once rigorous curr. decided AND (RORHSDT_AP_IB_COURSES = 'Y' OR RORHSDT_REQ_COURSES='Y')*/
        AND RORHSDT_REQ_COURSES='Y'
        AND sgbstdn_stst_code = 'AS'
        AND  SGBSTDN_STYP_CODE IN ('F','H','T')
        AND (SORLCUR_DEGC_CODE LIKE 'B%' OR SORLCUR_DEGC_CODE LIKE 'A%'
        OR SORLCUR_DEGC_CODE = 'UND')
        AND sorlcur_seqno = (SELECT MAX(sorlcur_seqno)
                              FROM sorlcur
                              WHERE sorlcur_pidm = A.sgbstdn_pidm
                              AND sorlcur_term_code = &enrollment_term)
        AND  SORLCUR_CACT_CODE='ACTIVE' 
        AND rorenrl_term_code = &enrollment_term
        AND shrlgpa_hours_earned BETWEEN 0 AND 29
        AND shrlgpa_gpa_type_ind = 'O'
        AND rorstat_pckg_comp_date IS NOT NULL
        AND  A.SGBSTDN_TERM_CODE_EFF = (SELECT MAX(B.SGBSTDN_TERM_CODE_EFF)
                                                                            FROM SGBSTDN B
                                                                             WHERE B.SGBSTDN_PIDM = A.SGBSTDN_PIDM
                                                                             AND sgbstdn_term_code_eff <= &enrollment_term
        AND NOT EXISTS (SELECT 'X'
                                        FROM RPRAWRD
                                      WHERE RCRESAR_PIDM = RPRAWRD_PIDM
                                          AND RCRESAR_AIDY_CODE = RPRAWRD_AIDY_CODE
                                          AND RPRAWRD_FUND_CODE = 'ACG1')
         AND rorstat_pidm = rcresar_pidm
        AND spriden_pidm = rcresar_pidm
        AND  RCRAPP1_PIDM    = RCRESAR_PIDM 
        AND shrlgpa_pidm = rcresar_pidm
        AND  SORHSCH_PIDM   = RCRESAR_PIDM 
        AND  RORHSDT_PIDM   = RCRESAR_PIDM 
        AND  SGBSTDN_PIDM   = RCRESAR_PIDM    
        AND  SORLCUR_PIDM   = RCRESAR_PIDM 
        AND rnvand0_pidm = rorstat_pidm
        AND  RCRESAR_INFC_CODE = RCRAPP1_INFC_CODE 
        AND  RCRESAR_SEQ_NO      = RCRAPP1_SEQ_NO  
        AND  RCRAPP1_AIDY_CODE = RCRESAR_AIDY_CODE
        AND ROBINST_AIDY_CODE = RCRESAR_AIDY_CODE
        AND  RCRESAR_AIDY_CODE = '&AIDY_CODE'
        AND rorstat_aidy_code = rcresar_aidy_code
        AND rnvand0_aidy_code = rcresar_aidy_code
        AND spriden_change_ind IS NULL
        ORDER BY name

    Frank Kulash wrote:
    Hi
    blackhole82 wrote:
    Yeah I realized that I was probably mixing styles after it wouldn't work. What you suggested does execute, so I assume it's right even though I'm not getting any rows at the moment. Don't assume it's correct: verify it
    I suggest re-writing the query using all ANSI syntax.
    Start with just two tables. Make sure that join is working.
    When you have something that works perfectly with just those tables, then add one more table.
    So if I wanted to left outer join onto shrlgpa too I would just need to add that underneath the join for rorenrl before the , and SORLCUR?In your existing query, it looks like shrlgpa is only connected to rcresar, using an inner join. Do you want to change that?At any rate, the order of tables using the old doesn't matter. Using ANSI notation, however, a join condition can only reference tables that have already been named in the same group of ANSI-joined tables.
    So you would probably would have to re-arrange the FROM clause.
    Sorry, I don't understand exactly what you want to do, so I can't tell you exactly how to do it.
    Make you best guess, and try it.
    If it doesn't produce the results you want, and you can't figure out how to fix it, then post the query, some sample data, and the desired results. If you post just the revised query, and a description of the problem, I'll try to answer, but without the sample data and desired results I can't guarantee that I can.Well I'm getting rows and the data seems to go with the query I had before using the outer join except for the records that have no record on shrlgpa. It appears that by having the clauses
    AND shrlgpa_hours_earned BETWEEN 0 AND 29
    AND shrlgpa_gpa_type_ind = 'O'that those I'm trying to pull in with the left outer join are being eliminated. Is it possible to still limit the hours earned while pulling in those who do not have a record on shrlgpa? Before I was just using a UNION to accomplish this, but I thought that I might be able to fine tune the query to eliminate the need for another UNION.

  • Help with left outer join

    Hi,
    I Have this database structure:
    Artist(IDA,Name,Year_b)
    Work(IDW,Title,IDA,IDL)
    City(IDL,IName,Nation)
    I Want to do a query that retrieve for one Artist all Works availables on database and,if present,the City where each work was realized.
    This SQL code is correct?
    SELECT Name,Title,IName
    FROM Artist a,
    Work w LEFT OUTER JOIN City c ON w.IDL=c.IDL
    WHERE w.IDA=a.IDA and a.IDA='2';
    If it's not correct, what type of correction need it?
    Thanks for Help
    Andrea

    If you asked... The original query works, but it is not "right".
    You should use either the old Oracle style of joins, like in the VM's query, or, better, the ANSI join style, recommended by Oracle (not a mix of them, like in your query):
    SELECT a.name,
           w.title,
           c.iname
    FROM  artist a
    JOIN  work  w
       ON  w.ida = a.ida
    LEFT OUTER JOIN city c
       ON  w.idl = c.idl
    WHERE  a.ida = '2'

  • Can we join 3 tables with left outer join

    hi friends.
          Can any one tell how to join 3 tables using <b>left outer join</b>...i tried by taking some fields of <b>ekko,ekpo,eket</b>, but this not working ... plz give a sample code with some fields.

    Hi Uday
    <b>Inner joins using 3 tables </b>
    <i><b>Try this :-</b></i>
    SELECT stpo~stlnr stpo~idnrk mast~matnr mara~mtart stpo~menge 
    INTO CORRESPONDING FIELDS OF TABLE zmat1 FROM mast 
    JOIN stpo ON stpo~stlnr = mast~stlnr 
    JOIN mara ON mara~matnr = mast~matnr 
    WHERE stpo~stlty = 'M' "AND stpo~idnrk IN s_matnr 
    AND mast~werks = 1000.
    <b><i>Here s_matnr is a select-options on the selection-screen. </i></b>
    <i><b>Or this. </b></i>
    <b>Code: </b>
         Select single Vbrk~Bukrs Vbrk~Kunrg    Vbrk~Vbeln 
                       Vbrk~Fkdat Vbrk~Bstnk_Vf Vbrk~Zterm 
                       Tvzbt~Vtext 
                       Vbak~Vbeln Vbak~Bstdk 
                       Likp~Vbeln Likp~lfdat    Likp~Lfuhr 
           into w_vbrk 
           from vbrk 
          inner join       Tvzbt on Tvzbt~Zterm        = Vbrk~Zterm      and 
                                    Tvzbt~Spras        = sy-langu 
          Inner join       Vbfa  as SalesLnk 
                                 on SalesLnk~vbeln     = pu_vbeln        and 
                                    SalesLnk~vbtyp_v   = c_order 
                inner join Vbak  on Vbak~Vbeln           = SalesLnk~Vbelv
          Inner join       Vbfa  as DeliveryLnk 
                                 on DeliveryLnk~vbeln   = pu_vbeln       and 
                                    DeliveryLnk~vbtyp_v = c_Delivery 
                inner join Likp  on Likp~Vbeln          = DeliveryLnk~Vbelv 
          where vbrk~vbeln = pu_Vbeln.
    <i><b>This code locates sales, delivery and payment terms info from a billing document number.</b></i> 
    <i><b>or</b></i>
    <b>
    Here, this one also works fine :</b>
    select zfpcd~cadivi zfpcd~proforma zfpcd~factura zfpcd~aniofactura 
    zfpcd~montousd zfpcd~montoap zfpcd~ebeln zfpcd~inco1 
    zfpcd~lifnr lfa1~name1 zcdvs~status zfpcd~conint 
    into it_lista 
    from zfpcd inner join zcdvs 
    on zfpcd~ebeln = zcdvs~ebeln 
    and zfpcd~proforma = zcdvs~proforma 
    and zfpcd~lifnr = zcdvs~lifnr 
    inner join lfa1 
    on zfpcd~lifnr = lfa1~lifnr 
    where zcdvs~status = '04'.
    Reward if helpfull
    Regards
    Pavan

  • 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

  • Query with multiple outer joins

    I had a doubt with whether the following kind of query is valid with multiple outer-joins. The format of the query is something like this:-
    select A.col1, B.col2
    from table1 A, table2 B, table3 C where
    A.col3=B.col4(+) and B.col5=C.col6(+)
    This would mean the follwoing with regard to outer-joins in the query.
    1) fetch records with col3 in table A matching or not matching col4 in table B
    2) fetch records with col5 in table B matching or not matching col6 in table C
    So, this query is valid?
    I hope, my question is clear.
    Please, help in solving the doubt.
    regards

    This is valid and it works fine

  • BI 7.0 Infoset - Infocube - Left outer join - query

    Hi Expert,
    A infoset contain Infocube and ODS, linked with left outer join, common fields are PO,PO item.  PO account assignment ODS have three keyfields: PO Doc.,Item,account Assignment  .
         PO  Infocube                                     <b>PO Account Assignment ODS</b>
    PO       PO item  Amt<b>PO Doc.  Item   AccAssignment         Cost object</b>
    1000    10            230  <b>1000       10        1                          CC1</b>
    1001    10            250  <b>1002       10        1                          CC1</b>
    1002    10            150  <b>1002       10        2                          CC2</b>
    in BEx result are like this:    
    1000    10            230      1     CC1
    1001    10            250      #      #
    1002    10            150      1     CC1
    1002    10            150      2     CC2 ( amount only duplicated)
    The issue was that amount gets duplicated. It only occurs if PO has more than one account assignment.
    In report, we want show like this
    1000    10            230       1       CC1
    1001    10            250       #        #
    1002    10            150       1       CC1
    1002    10            #        2       CC2
    Any suggestion or input to overcome this issue?
    Thanks,
    Saran
    Message was edited by:
            Saravanan K

    Hi,
    did you solve your problem? because I have the same issue right now: the left outer join doesn't seem to do its job.
    Let me know if you have found a solution, it would be appreciated.
    have a nice day,
    Dominic

  • Using Left Outer Join along with reference

    I have three tables.
    Table 1 : BOOK_DETAILS
    Fields: BOOK_ID, BOOK_NAME
    Table 2: BOOK_ISSUE_RECORD
    Fields: BOOK_ID, USER_NAME
    Table 3: BOOK_AUTHOR
    Fields: BOOK_ID, AUTHOR_NAME
    I have to link Table 1 and Table 2 with Left outer Join because even if the book is not issues to anyone, its name should come.
    Again I have to display the Book Author name for each Book.
    I am able to create a query with the Left outer join between Table 1 and Table 2. However I am not able to give a reference to the Table 3.
    Can any one please help me with this.
    Regards
    Hawker

    select  d.book_name,
            a.book_author,
            i.user_name
      from       book_details d
            join
                 book_author a
              on (d.book_id = a.book_id)
            left join
                 book_issue_recors i
              on (d.book_id = i.book_id)
    /SY.

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

  • Ora-00904 left outer join

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

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

  • Using Command to fix null / left outer join issue

    Hi
    I was told awhile ago that it's possible to fix crystal's issue with left outer join and null records being eliminated.
    I think i remember most of how this goes, but i can't seem to duplicate it.
    1) You can't have any select expert -- record
    2) You create the report normally and then make a new report using the SQL Query
         - Can't remember if its the whole report or upto the tables that have hisotry (null results)
    3) You move parts from WHERE to FROM
    Hopefully someone can help correct the steps i'm doing wrong or add what i'm missing from this.
    Below is the Query from my comlpeted report, but when i run it with the last LEFT OUTER JOIN added it removes all the products with no sales during that year.
    Any help would be greatly appreciated even if it's to say this can't be done.
    SELECT
    "prod_warehouse"."pw_whs_id",
    "prod_warehouse"."pw_prodline_id",
    "prod_warehouse"."pw_prod_id",
    "prod_warehouse"."pw_bin_location1",
    "prod_warehouse"."pw_min_onhand_qty",
    "prod_warehouse"."pw_max_onhand_qty",
    "prod_warehouse"."pw_onhand_qty",
    "product_lookup"."prlkp_lang1_1_desc",
    "prod_customer"."prcu_cust_part_num",
    "contract_details"."cond_level1_amt",
    "sales_history"."sah_year"
    FROM   (((("sisl_data05"."dbo"."products" "products"
    LEFT OUTER  JOIN "sisl_data05"."dbo"."prod_warehouse" "prod_warehouse"
    ON ("products"."pr_prod_id"="prod_warehouse"."pw_prod_id")
    AND ("products"."pr_prodline_id"="prod_warehouse"."pw_prodline_id"))
    LEFT OUTER JOIN "sisl_data05"."dbo"."product_lookup" "product_lookup"
    ON ("products"."pr_prod_id"="product_lookup"."prlkp_prod_id")
    AND ("products"."pr_prodline_id"="product_lookup"."prlkp_prodline_id"))
    LEFT OUTER JOIN "sisl_data05"."dbo"."prod_customer" "prod_customer"
    ON ("products"."pr_prod_id"="prod_customer"."prcu_prod_id")
    AND ("products"."pr_prodline_id"="prod_customer"."prcu_prodline_id"))
    LEFT OUTER JOIN "sisl_data05"."dbo"."contract_details" "contract_details"
    ON "prod_warehouse"."pw_prod_id"="contract_details"."cond_prod_id")
    LEFT OUTER JOIN "sisl_data05"."dbo"."sales_history" "sales_history"
    ON (("prod_warehouse"."pw_whs_id"="sales_history"."sah_sortkey1")
    AND ("prod_warehouse"."pw_prod_id"="sales_history"."sah_sortkey2"))
    AND ("prod_warehouse"."pw_prodline_id"="sales_history"."sah_sortkey3")
    WHERE
    "prod_warehouse"."pw_whs_id"='20123'
    AND ("prod_warehouse"."pw_onhand_qty"<>0
    OR "prod_warehouse"."pw_bin_location1"<>'  '
    OR "prod_warehouse"."pw_max_onhand_qty">0)
    AND "sales_history"."sah_year"=2014
    ORDER BY "prod_warehouse"."pw_bin_location1", "prod_warehouse"."pw_prod_id"

    Try this:
    SELECT
    prod_warehouse.pw_whs_id,
    prod_warehouse.pw_prodline_id,
    prod_warehouse.pw_prod_id,
    prod_warehouse.pw_bin_location1,
    prod_warehouse.pw_min_onhand_qty,
    prod_warehouse.pw_max_onhand_qty,
    prod_warehouse.pw_onhand_qty,
    product_lookup.prlkp_lang1_1_desc,
    prod_customer.prcu_cust_part_num,
    contract_details.cond_level1_amt,
    sales_history.sah_year
    FROM sisl_data05.dbo.products products
      LEFT OUTER  JOIN sisl_data05.dbo.prod_warehouse prod_warehouse
        ON products.pr_prod_id=prod_warehouse.pw_prod_id
        AND products.pr_prodline_id=prod_warehouse.pw_prodline_id
      LEFT OUTER JOIN sisl_data05.dbo.product_lookup product_lookup
        ON products.pr_prod_id=product_lookup.prlkp_prod_id)
        AND products.pr_prodline_id=product_lookup.prlkp_prodline_id
      LEFT OUTER JOIN sisl_data05.dbo.prod_customer prod_customer
        ON products.pr_prod_id=prod_customer.prcu_prod_id
        AND products.pr_prodline_id=prod_customer.prcu_prodline_id
      LEFT OUTER JOIN sisl_data05.dbo.contract_details contract_details
        ON prod_warehouse.pw_prod_id=contract_details.cond_prod_id
      LEFT OUTER JOIN sisl_data05.dbo.sales_history sales_history
        ON prod_warehouse.pw_whs_id=sales_history.sah_sortkey1
        AND prod_warehouse.pw_prod_id=sales_history.sah_sortkey2
        AND prod_warehouse.pw_prodline_id=sales_history.sah_sortkey3
        AND sales_history.sah_year = 2014
    WHERE prod_warehouse.pw_whs_id='20123'
      AND (prod_warehouse.pw_onhand_qty<>0
        OR prod_warehouse.pw_bin_location1<>'  '
        OR prod_warehouse.pw_max_onhand_qty>0)
    Take a look at what I've done with the last line of the last join.  The issue is that when you left join to a table and you use that table in the Where clause, you've basically turned your you left outer join into an inner join because the record has to be there in order to get the value in the filter.  By moving the filter into the join, you'll still get the rest of the data when there is no corresponding record.
    NOTE:  Crystal adds all sorts of "extra" stuff like quotes and parentheses that you don't need and which I have removed to make the query easier to read.
    -Dell

  • Restriction to Left Outer Joins in PS Query

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

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

  • Issue on left outer join query in 10G

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

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

Maybe you are looking for

  • Locking mechanism provided by the Web AS Java

    Hi All, I have a requirement to lock an object for a specific action with using locks provided and managed by the Web AS Java (i have to use TableLocking API). I have read about the locking mechanism in "SAP NetWeaver Developer Studio Documentation h

  • Server does not support remote front panels

    hello I'm about to command the front of my labview program remotely. I followed all the steps that I found on the NI website. when I do the test on my Intenet Explorer browser it gives me the following mesage: "Server does not support remote front pa

  • Error running J2EE App on Web AS 6.40

    Hi all experts, I'm triying to implement JSPWiki on Web As 6.40 SP17, I've followed the instructions this blog /people/pankaj.kumar32/blog/2005/09/10/wiki-wiki-world-and-portals This is what a did: 1.- Downlowded the latest version of JSPWiki from ht

  • Can I make two differents selection screen in my program?

    Hi experts!! I don't know how to male this, the problem is that I need to make two differents selection screen in my program because I have two differents kinds of button, BUTTON1         BUTTON2          BUTTON3 When I press button1 I received. BUTT

  • Infinity set up info query

    HH5 arrived this morning ready for wed set up. Installed it and wired and wireles working ok. The query I have is do I connect vision+ box  same as HH4 with the ethernet cable to HH5? and do I need to do anything else after cab visit on wednesday? Th