Ansi outer join question

I am on Oracle 10g.
I believe the following two statements are equivalent.
This statement returns the correct results
select k.key, NVL(v.value, k.en_value) as lvalue
from sku_key k, sku_key_value v
WHERE k.id_sku_key = v.id_sku_key (+)
and k.id_sku_key = 5
and v.id_sku_language (+) = 33;
This statement returns no results (however, if I remove the line "and v.id_sku_language = 33" then results are returned, just not the correct results).
select k.key, NVL(v.value, k.en_value) as lvalue
from sku_key k LEFT JOIN sku_key_value v ON k.id_sku_key = v.id_sku_key
where k.id_sku_key = 5
and v.id_sku_language = 33;
What needs to be done to the ANSI JOIN statement to make it equivalent to the (+) join statement?
Thanks,
John

This change fixes the problem:
select k.key, NVL(v.value, k.en_value) as lvalue
from sku_key k
LEFT JOIN sku_key_value v ON (k.id_sku_key = v.id_sku_key
and (v.id_sku_language = 33
or v.id_sku_language is null))
where k.id_sku_key = 5

Similar Messages

  • Non-ANSI Outer Join Operator Issue (reposted due to text issues)

    I am currently using Designer 11.5.0.0. Itu2019s XI Rel 2, but Iu2019m not sure what service pack. I have created several universes with outer joins against a SQL Server 2005 database, but when I try using them in a Crystal report, I get the following error:
    Failed to retrieve date from the database. Details: 42000:[Microsoft][ODBC SQL Server Driver][SQL Server] The query uses non-ANSI outer join operators (u201C=u201D or u201C=u201D). To run this query without modification, please set the compatibility level for current database to 80 or lower, using stored procedure sp_dbcmptlevel. It is strongly recommended to rewrite the query using ANSI outer join operators (LEFT OUTER JOIN, RIGHT OUTER JOIN). In the future versions of SQL Server, non-ANSI join operators will not be supported even in backward-compatibility modes.
    Here is my ODBC DSN configuration:
    Microsoft SQL Server ODBC Driver Version 03.85.1132
    Data Source Name: FlexOPS
    Data Source Description:
    Server: dalsvrw031
    Database: (Default)
    Language: (Default)
    Translate Character
    Data: Yes
    Log Long Running Queries: No
    Log Driver Statistics: No
    Use Integrated Security: No
    Use Regional Settings: No
    Prepared Statements Option: Drop temporary procedures on disconnect
    Use Failover Server: No
    Use ANSI Quoted Identifiers: Yes
    Use ANSI Null, Paddings and Warnings: Yes
    Data Encryption: No
    Okay, so I understand what the issue is. It appears that the version of Designer that I am using does not default the ANSI92 parameter to u201CYesu201D. So all the outer joins I have created in each of my universe are using the old *= as the join operator. And apparently, the ODBC driver I am using is not very happy with that.
    As I understand it from what Iu2019ve read on other sites, I have the following options:
    1) Set the ANSI92 parameter to Yes, drop all my joins, close and re-open Designer, and recreate all of the joins.
    2) Find a different driver or connectivity method that will support non-ANSI joins.
    3) Set my database back to SQL 2000 compatibility.
    Option 1 is unappealing as it will cause a lot of time redoing all the work that Iu2019ve spent the past month doing. Option 2 is only a band-aid fix at best. Option 3 really isnu2019t an option for us.

    So I am wondering what other options I have to change these non-ANSI joins to ANSI compatible joins. Do I need to update Designer with a service pack? Is there a script out there that will automatically do this in each of the universes? I would appreciate any suggestions or guidance on this.
    Thanks,
    Lee

  • Non-ANSI Outer Join Operator Issue

    I am currently using Designer 11.5.0.0.  Itu2019s XI Rel 2, but Iu2019m not sure what service pack.  I have created several universes with outer joins against a SQL Server 2005 database, but when I try using them in a Crystal report, I get the following error:
    Failed to retrieve date from the database.
    Details:  42000:[Microsoft][ODBC SQL Server Driver][SQL Server] The query uses non-ANSI outer join operators (u201C=u201D or u201C=u201D).  To run this query without modification, please set the compatibility level for current database to 80 or lower, using stored procedure sp_dbcmptlevel.  It is strongly recommended to rewrite the query using ANSI outer join operators (LEFT OUTER JOIN, RIGHT OUTER JOIN).  In the future versions of SQL Server, non-ANSI join operators will not be supported even in backward-compatibility modes.
    Here is my ODBC DSN configuration:
    Microsoft SQL Server ODBC Driver Version 03.85.1132
    Data Source Name: FlexOPS
    Data Source Description:
    Server: dalsvrw031
    Database: (Default)
    Language: (Default)
    Translate Character Data: Yes
    Log Long Running Queries: No
    Log Driver Statistics: No
    Use Integrated Security: No
    Use Regional Settings: No
    Prepared Statements Option: Drop temporary procedures on disconnect
    Use Failover Server: No
    Use ANSI Quoted Identifiers: Yes
    Use ANSI Null, Paddings and Warnings: Yes
    Data Encryption: No
    Okay, so I understand what the issue is.  It appears that the version of Designer that I am using does not default the ANSI92 parameter to u201CYesu201D.  So all the outer joins I have created in each of my universe are using the old *= as the join operator.  And apparently, the ODBC driver I am using is not very happy with that.
    As I understand it from what Iu2019ve read on other sites, I have the following options:
    1)   Set the ANSI92 parameter to Yes, drop all my joins, close and re-open Designer, and recreate all of the joins.
    2)   Find a different driver or connectivity method that will support non-ANSI joins.
    3)   Set my database back to SQL 2000 compatibility.
    Option 1 is unappealing as it will cause a lot of time redoing all the work that Iu2019ve spent the past month doing.  Option 2 is only a band-aid fix at best.  Option 3 really isnu2019t an option for us.
    So I am wondering what other options I have to change these non-ANSI joins to ANSI compatible joins.  Do I need to update Designer with a service pack?  Is there a script out there that will automatically do this in each of the universes?
    I would appreciate any suggestions or guidance on this.
    Thanks,
    Lee
    Edited by: Lee Vance on Jul 6, 2009 10:02 PM

    Hi,
    try the following:
    open your universe in the Universe designer, go to File->Parameter, select the Parameter tab and change the value of the ANSI92 parameter from No to Yes.
    Regards,
    Stratos

  • Newbie: Syntax for OUTER joins

    Hello there,
    I'm trying to write some very simple ANSI outer joins using quest's TOAD software but I keep running into syntax errors.
    Take the following classic text book example
    Find all customers who have not placed an order
    SELECT c.customerid, o.orderid
    FROM customers c
    LEFT OUTER JOIN orders o
    ON c.customerid = o.customerid
    WHERE o.orderid IS NULL
    alternative syntax supported by SQL Server
    SELECT c.customerid, o.orderid
    FROM customers c, orders o
    WHERE c.customerid *= o.customerid AND o.orderid IS NULL
    How do you write the above style of statements. Can you write RIGHT JOIN and FULL JOIN statements? What about CROSS JOIN statements
    Cheers,
    Colin Rippey
    null

    SELECT c.customerid, o.orderid
    FROM customers c, orders o
    WHERE
    c.customerid = o.customerid(+) and
    o.orderid IS NULL
    null

  • Help on "Left Outer Join" migration

    Can somebody help me convert the following join to Oracle, thanks.
    SELECT ...
    FROM ats
    LEFT OUTER JOIN vw_S sv ON ats.SID = sv.SID AND ats.R <> 'H'
    LEFT OUTER JOIN vw_P ag ON ats.AID = ag.AID
    The Workbench said "Manual conversion required"

    Hi Jimmy,
    Oracle 9i now supports ISO/ANSI outer join syntax
    So no changes are required.
    T-SQL
    SELECT ...
    FROM ats
    LEFT OUTER JOIN vw_S sv ON ats.SID = sv.SID AND ats.R <> 'H'
    LEFT OUTER JOIN vw_P ag ON ats.AID = ag.AID
    Oracle 9i (has ISO/ANSI Join Syntax)
    SELECT ...
    FROM ats
    LEFT OUTER JOIN vw_S sv ON ats.SID = sv.SID AND ats.R <> 'H'
    LEFT OUTER JOIN vw_P ag ON ats.AID = ag.AID
    Oracle 8i
    SELECT ...
    FROM ats , vw_S sv , vw_P ag
    WHERE ats.SID = sv.SID (+)
    AND ats.R <> 'H'
    AND ats.AID = ag.AID (+)
    I have not tested the above but I believe they are equivalent.
    I hope this helps
    Dermot.

  • Left Outer Join Problem for Multiple Condition

    Hi This is the code and I want to return the vlaues evens if it is not ther so my Sysntax is not right for that can you plz help me
    SELECT ap.descripcion AS Production_Description,
    conceptes.descripcion AS Concepts_Description ,
    um.Nomenclatura AS Unit_Measure ,
    -- real_daily_detail.FechaProduccion AS Production_Date ,
    period.Codigo as June,
    period.anio AS YEAR_08 ,
    rmd.Valor AS Values_Monthly,
    budgetd.Valor as Budget
    FROM sgr_area_produccion ap ,
    sgr_conceptos conceptes ,
    SGR_Unidad_Medida um ,
    SGR_Unidad_Produccion up ,
    SGR_Unidad_Area_Produccion uap ,
    SGR_Real_Mensual_Detalle rmd ,
    SGR_Periodo period ,
    SGR_Real_Mensual rm ,
    SGR_Presupuesto budget ,
    SGR_Presupuesto_Detalle budgetd
    where uap.ID_Unidad_Produccion = up.ID_Unidad_Produccion (+)
    and uap.ID_Area_Produccion = ap.ID_Area_Produccion (+)
    and rm.ID_Area_Produccion = uap.ID_Area_Produccion (+)
    and rm.ID_Unidad_Produccion = uap.ID_Unidad_Produccion (+)
    and rmd.ID_Unidad_Produccion = rm.ID_Unidad_Produccion (+)
    and rmd.ID_Area_Produccion = rm.ID_Area_Produccion (+)
    and rmd.ID_Periodo = rm.ID_Periodo (+)
    and period.ID_Periodo = rm.ID_Periodo (+)
    and conceptes.ID_Concepto = rmd.ID_Concepto (+)
    and budget.ID_Unidad_Produccion = uap.ID_Unidad_Produccion(+)
    and budget.ID_Area_Produccion = uap.ID_Area_Produccion (+)
    and budget.ID_Unidad_Produccion = budgetd.ID_Unidad_Produccion
    and budget.ID_Area_Produccion = budgetd.ID_Area_Produccion (+)
    and budget.ID_Periodo = budgetd.ID_Periodo (+)
    and period.ID_Periodo = budget.ID_Periodo (+)
    and period.Codigo = 'JUNIO-08'
    and conceptes.ID_Concepto = budgetd.ID_Concepto (+)
    and daily.ID_Area_Produccion = uap.ID_Area_Produccion (+)
    and daily.ID_Unidad_Produccion = uap.ID_Unidad_Produccion (+)
    and dailyd.ID_Unidad_Produccion = daily.ID_Unidad_Produccion(+)
    and dailyd.ID_Area_Produccion = daily.ID_Area_Produccion (+)
    and period.ID_Periodo = daily.ID_Periodo (+)
    and conceptes.ID_Concepto = dailyd.ID_Concepto (+)
    and um.ID_Unidad_Medida = conceptes .ID_Unidad_Medida (+)

    Oracle old outer join syntax had more restrictions than more recent ANSI outer join syntax. I do'nt want to emulate compiler and go through your code to spot any possible problems, even more if you cannot say also the exact error or exact problem what you get.
    And bear in mind that for outer joins THERE IS DIFFERENCE [url http://www.gplivna.eu/papers/sql_join_types.htm#p6.4]between join conditions and predicates in where clause.
    Gints Plivna
    http://www.gplivna.eu

  • SQL7 to ORA9i problem w/ outer joins

    The information provided for the new release 9.2.0.1.7 of the Migration workbench explained that outer joins would be easier to convert with the added parse options. I have several stored procedures with outer joins that are still giving warning errors with the latest version. I have selected the parse options to generate Oracle 8i outer joins and have also left it unchecked. I continue to get the same errors for the outer joins. Here is an example of the join:
    (SELECT DISTINCT Product_tblProductRegion.ProductRegion_ID
    FROM Product_tblProductRegion LEFT JOIN Product_tblMaster ON Product_tblProductRegion.ProductRegion_ProductID = Product_tblMaster.Product_ID
    WHERE Product_tblMaster.Product_ID Is Null)
    Please let me know what information is needed to work through this problems.
    Thank you.

    Logged bug, Bug No: 3393782
    The workaround is to manually copy the ANSI Outer join from the TSQL to PLSQL. There appears to be a conflict between two fixes in the code, the ANSI join fix and the table function code, which is applicable to sqlserver 2k.
    Turloch

  • URGENT - need help with ansi/iso outer joins

    Hi,
    I am currently preparing for the OCP sql exam for the 9i developer track and I think a statement is printed wrong in my study book, please could somebody confirm the following:-
    Oracle Outer Join syntax
    from tab_a, tab_b
    where a.col_1 (+) = b.col_1
    ANSI/ISO Equivalent
    from tab_a a left outer join tab_b b
    on a.col_1 = b.col_1
    Should n't the above be a right outer join
    Please could somebody confirm or explain if I am wrong.
    Thanks in anticipation.
    Simon
    Note. The book is OCP Introduction to 9i sql (1Z0-007) page 115 (table 3-1) - author Jason Couchman

    It seems so....
    See
    http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96540/statements_103a.htm#2107297

  • ANSI SQL 92 SYNTAX OUTER JOIN PERFORMANCE ISSUE

    Good Morning
    Could anyone explain why the excution time for these two (ment to be identical)
    queries run so differently.
    oracle syntax execution time 1.06 seconds
    select COUNT(*) from
    PL_EVENT_VIEW pev,
    PL_EVENT_STAFF_VIEW pesv
    WHERE pev.EVENT_ID=PESV.EVENT_ID(+)
    AND pev.WEEKS=PESV.WEEK_NUM(+)
    AND pev.event_id=2520
    ansi sql 92 syntax execution time 7.05 seconds
    select COUNT(*) from
    PL_EVENT_VIEW pev
    LEFT JOIN PL_EVENT_STAFF_VIEW pesv
    ON (pev.EVENT_ID=PESV.EVENT_ID
    AND pev.WEEKS=PESV.WEEK_NUM)
    WHERE pev.event_id=2520
    Thanks
    David Hills

    BTW Oracle outer join operator (+) and ANSI SQL OUTER JOIN syntax are NOT equivalent. Consider following:
    DROP TABLE T1;
    CREATE TABLE T1 (C1 NUMBER);
    DROP TABLE T2;
    CREATE TABLE T2 (C2 NUMBER);
    DROP TABLE T3;
    CREATE TABLE T3 (C3 NUMBER);
    -- Following SELECT works:
    SELECT COUNT(*)
         FROM T1, T2, T3
         WHERE C2 = C1
              AND C3(+) = C1
    COUNT(*)
    0
    -- But:
    SELECT COUNT(*)
         FROM T1, T2, T3
         WHERE C2 = C1
              AND C3(+) = C1
              AND C3(+) = C2
    AND C3(+) = C1
    ERROR at line 4:
    ORA-01417: a table may be outer joined to at most one other table
    -- However with ANSI syntax:
    SELECT COUNT(*)
         FROM T1
         JOIN T2 ON (C2 = C1)
         LEFT JOIN T3 ON (C3 = C1 AND C3 = C2)
    COUNT(*)
    0

  • Question on using the outer join

    SELECT
    SIAP.FLIGHT_PROCEDURE.PROC_CNTL_NUMBER,
    SIAP.FLIGHT_PROCEDURE.PROCEDURE_NAME,
    SIAP.FLIGHT_PROCEDURE.AMENDMENT_NUMBER,
    FLOOR (flight_procedure.amendment_number),
    CHR ( ( flight_procedure.amendment_number
    - FLOOR (flight_procedure.amendment_number))
    * 100
    SIAP.FLIGHT_PROCEDURE.FACILITY_IDENT,
    SIAP.PROC_AIRPORT.AIR_ID,
    SIAP.PROC_AIRPORT.NAME,
    SIAP.PROC_AIRPORT.LOCATION,
    SIAP.PROC_AIRPORT.STATE_CODE,
    SIAP.PROC_AIRPORT.COUNTRY_CODE,
    SIAP.FLIGHT_PROCEDURE.EFFECTIVE_START_DATE,
    SIAP.FLIGHT_PROCEDURE.STATUS_IND,
    APTS.APTS_TASK.TASK_DESCRIPTION,
    APTS.APTS_TASK.IFP_CNTRL_NO,
    APTS.APTS_TASK.IFP_RCNTRL_NO,
    APTS.APTS_TASK.IFP_CNTRL_REF,
    APTS.APTS_TASK.IFP_RCNTRL_REF
    FROM
    APTS.APTS_TASK,
    SIAP.PROC_AIRPORT,
    SIAP.FLIGHT_PROCEDURE
    WHERE
    ( SIAP.FLIGHT_PROCEDURE.PROC_CNTL_NUMBER=SIAP.PROC_AIRPORT.PROC_CNTL_NUMBER )
    AND ( SIAP.FLIGHT_PROCEDURE.AMENDMENT_NUMBER=SIAP.PROC_AIRPORT.AMENDMENT_NUMBER )
    AND APTS.APTS_TASK.IFP_CNTRL_NO = TO_CHAR (flight_procedure.proc_cntl_number)(+)
    AND APTS.APTS_TASK.IFP_RCNTRL_NO = flight_procedure.amendment_number(+)
    I want to get all the records from APTS_TASK table even if they do not exist in SIAP.FLIGHT_PROCEDURE. So I have created a outer join APTS_TASK table and flight_procedure table to get all the records from APTS. I get all the records if I use just the two tables APTS_TASK and FLIGHT_PROCEDURE. But when I include SIAP.PROC_AIRPORT in the query I loose some records from the query. So If I want to get all the records should I include all the outer join to SIAP. PROC_AIRPORT table too. I tried to make this clear but let me know if you have more questions.

    SELECT
    SIAP.FLIGHT_PROCEDURE.PROC_CNTL_NUMBER,
    SIAP.FLIGHT_PROCEDURE.PROCEDURE_NAME,
    SIAP.FLIGHT_PROCEDURE.AMENDMENT_NUMBER,
    FLOOR (flight_procedure.amendment_number),
    CHR ( ( flight_procedure.amendment_number
    - FLOOR (flight_procedure.amendment_number))
    * 100
    SIAP.FLIGHT_PROCEDURE.FACILITY_IDENT,
    SIAP.PROC_AIRPORT.AIR_ID,
    SIAP.PROC_AIRPORT.NAME,
    SIAP.PROC_AIRPORT.LOCATION,
    SIAP.PROC_AIRPORT.STATE_CODE,
    SIAP.PROC_AIRPORT.COUNTRY_CODE,
    SIAP.FLIGHT_PROCEDURE.EFFECTIVE_START_DATE,
    SIAP.FLIGHT_PROCEDURE.STATUS_IND,
    APTS.APTS_TASK.TASK_DESCRIPTION,
    APTS.APTS_TASK.IFP_CNTRL_NO,
    APTS.APTS_TASK.IFP_RCNTRL_NO,
    APTS.APTS_TASK.IFP_CNTRL_REF,
    APTS.APTS_TASK.IFP_RCNTRL_REF
    FROM
    APTS.APTS_TASK,
    SIAP.PROC_AIRPORT,
    SIAP.FLIGHT_PROCEDURE
    WHERE
    ( SIAP.FLIGHT_PROCEDURE.PROC_CNTL_NUMBER=SIAP.PROC_AIRPORT.PROC_CNTL_NUMBER )
    AND ( SIAP.FLIGHT_PROCEDURE.AMENDMENT_NUMBER=SIAP.PROC_AIRPORT.AMENDMENT_NUMBER )
    AND APTS.APTS_TASK.IFP_CNTRL_NO = TO_CHAR (flight_procedure.proc_cntl_number)(+)
    AND APTS.APTS_TASK.IFP_RCNTRL_NO = flight_procedure.amendment_number(+)
    AND SIAP.PROC_AIRPORT.PROC_CNTL_NUMBER = AIRPORT.PROC_CNTL_NUMBER
    AND SIAP.PROC_AIRPORT.REVISION NUMBER=AIRPORT.REVISION NUMBERIf I add the airport table also to the join like shown above,should I also do the cascading join to the proc_airport.

  • Outer Join Negation Question

    I'm retrofitting an existing plsql report into BusinessObjects. I have a question about
    the sql I'm looking at. There is an employee table and a case table. Employees have cases. There are two other tables...a case activity table and a case results table. There may or may not be activity and results for a given case. The query is this...
    select count(distinct case_id)
    employee.employee_id = case.employee_id
    and case.case_id = case_activity.case_id (+)
    and case.case_id = case_results.case_id (+)
    so far so good. The next part is
    and (case_activity.activity_date <= mm/dd/yyyy
    or case_results.activity_date <= mm/dd/yyyy)
    That cancels the outer join, right? I contend that there is no
    reason for the outer join symbols. He says they're needed. He thinks the OR is making a difference. It looks to me like you've lost the guarantee that all cases will be included. Can someone please splain this to me :-)
    Thanks so much!
    Cindy

    Cindy,
    I hope there's not too much of an arguement brewing on that query, but both of you are correct (to a degree). The OR in that second clause makes all the difference. I have some sql to show some test results based on your query. Basically remeber this, you always get one row back when making a query, if ALL conditions are met you get that record back. So even if the first part of the OR failes and the second one is true then u get the row back.
    Here's where that other fellow is having a problem though. The problem your going to have is when neither of thoes dates return ture then you get NO data back regardless of the outter joins. Thoes two table Activity and Results will become related if thought about like this. What I mean, is if there is a date in the Activity table that matches, then you will get the Result data as well, and vice-versa. However if there is neither Activity or Result date matches you loose the whole case record even though you have the outter join specified. UNLESS thats the whole point of that DATE range. If neither match then I dont want any case records back. I'm just assuming since your outter joining you want the case back the case regardless if there are matches or not in Activity and Results, but maybe this isn't so.
    Anyway, here some SQL for you and the data that produced it ...
    Tables (t1,t2,t3,t4) : t1is employee, t2 is case t3 is activity and t4 is result.
    Columns (c1,n1,d1) : varchar ID , number ID and a date
    All dates are set for today (Arpil 5, 2002)
    Data is the same in ALL the tables, only interested in C1= A and N1 = 1 from main table T1
    Table T1 has 1 record where C1= 'A' and N1= 1
    SQL> select c1,n1,d1 from t1 where c1='A' and n1=1;
    C1 N1 D1
    A 1 05-APR-02
    Case #1 (BOTH t3 and t4 have no matches)
    SQL> select DISTINCT
    2 t1.c1 "t1_c1",t1.n1 "t1_n1",
    3 t2.c1 "t2_c1",t2.d1 "t2_d1",t2.n1 "t2_n1",
    4 t3.c1 "t3_c1",t3.d1 "t3_d1",t3.n1 "t3_n1",
    5 t4.c1 "t4_c1",t4.d1 "t4_d1",t4.n1 "t4_n1"
    6 from t1,t2,t3,t4
    7 where
    8 (
    9 t1.C1 = t2.C1 and
    10 t2.c1 = t3.c1 (+) and
    11 t2.c1 = t4.c1 (+) and
    12 (T3.D1 <= to_date('2002/04/04','yyyy/mm/dd') or T4.D1 <= to_date('2002/04/04','yyyy/mm/dd'))
    13 )
    14 ;
    no rows selected
    This SQL produces no data as BOTH dates in t3 (Activity) and t4 (Results) have no matches since all D1 are set to today. Even though there is an outter join the whole [ ( date match t3 OR date match t4 ) ] fails so no records (or cases) get produced).
    The below Case #2 I changed the columns selected to a COUNT since this query would produce too much data to make of any sence in there. Besides, and I hope you oracle folks read this, the FONT makes any kind of query output impossible read. Ahhhhh I'm making something better at the moment for the public anyway.
    SQL> select DISTINCT
    2 count(t1.c1),count(t2.c1),count(t3.c1),count(t4.c1)
    3 from t1,t2,t3,t4
    4 where
    5 (
    6 t1.C1 = t2.C1 and
    7 t2.c1 = t3.c1 (+) and
    8 t2.c1 = t4.c1 (+) and
    9 (T3.D1 <= to_date('2002/04/04','yyyy/mm/dd') or T4.D1 <= to_date('2002/04/04','yyyy/mm/dd'))
    10 )
    11 AND t1.c1 ='A' AND T1.N1 = 1;
    COUNT(T1.C1) COUNT(T2.C1) COUNT(T3.C1) COUNT(T4.C1)
    0 0 0 0
    So as you can see with BOTH dates not having any matches you get no data back at all even with the outer joins. So yes in this case it does not matter if your outer joinning or not, the whole date clause falied and since it id ANDed to the whole where clause , the whole where clause fails and you get no data.
    Case #2 (table t3 has a date match but non in t4) : Only change to SQL was change the DAY from 04 to 05 ;being today). Bascially you get ALL the data from t1,t2,t3 AND t4. The record entries in T4 still show up even though there are no matches and the data from t4 shows up, it is not null.
    SQL> select DISTINCT
    2 count(t1.c1),count(t2.c1),count(t3.c1),count(t4.c1)
    3 from t1,t2,t3,t4
    4 where
    5 (
    6 t1.C1 = t2.C1 and
    7 t2.c1 = t3.c1 (+) and
    8 t2.c1 = t4.c1 (+) and
    9 (T3.D1 <= to_date('2002/04/05','yyyy/mm/dd') or T4.D1 <= to_date('2002/04/04','yyyy/mm/dd'))
    10 )
    11 AND t1.c1 ='A' AND T1.N1 = 1;
    COUNT(T1.C1) COUNT(T2.C1) COUNT(T3.C1) COUNT(T4.C1)
    8 8 8 8
    And no I didn't just chage the count numbers to 8. Notice though you still get t4 matches since the ID join is true, even though the dates are not. If you only wanted T3 records out then you would have to split out the t3 date and the t4 date from that OR clause. The same results occur if T4 has date mathces and T3 does not. Same result if BOTH have matches in t3 and t4.
    Case #3 : both t3 and t4 have no matches on date (both are set to yesterday, same as case #1) but you will want the data returned. Since the ID exists in both t3 and t4, but the dates do not, by adding another OR clause your OUTER joins will work ...
    SQL> select DISTINCT
    2 count(t1.c1),count(t2.c1),count(t3.c1),count(t4.c1)
    3 from t1,t2,t3,t4
    4 where
    5 (
    6 t1.C1 = t2.C1 and
    7 t2.c1 = t3.c1 (+) and
    8 t2.c1 = t4.c1 (+) and
    9 (T3.D1 <= to_date('2002/04/04','yyyy/mm/dd') or T4.D1 <= to_date('2002/04/04','yyyy/mm/dd'))
    10 )
    11 OR
    12 (
    13 t1.C1 = t2.C1 and
    14 t2.c1 = t3.c1 (+) and
    15 t2.c1 = t4.c1 (+)
    16 )
    17 AND t1.c1 ='A' AND T1.N1 = 1;
    COUNT(T1.C1) COUNT(T2.C1) COUNT(T3.C1) COUNT(T4.C1)
    8 8 8 8
    You can try this your self if you like, but overall if any part of and AND clause failes, no matter if part of it had 100 OR clauses in one set of brackets, it all fails, even if you have outer joins.
    Have a kick butt weekend and good luck with your sql, email if you need anything :)
    Tyler
    [email protected]

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

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

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

  • Outer Join logic

    The following code is an example of how to perform an outer join, in this case with ReportQuery (thanks Doug):
            ExpressionBuilder eb = new ExpressionBuilder();
            ReportQuery rq = new ReportQuery(Employee.class, eb);
            rq.addAttribute("firstName");
            rq.addAttribute("lastName");
            rq.addAttribute("areaCode", eb.anyOfAllowingNone("phoneNumbers").get("areaCode"));
            List<ReportQueryResult> results =  (List<ReportQueryResult>) session.executeQuery(rq);My question is about the logic Toplink uses to generate the outer join statement with the "(+)" in the generated sql.
    Does Toplink only generate the join statement if the same attribute is chosen in the select statement (in the above example "areaCode")?
    Along the same line of questioning, does it matter which attribute was in the get() call? So, in the above example did it have to be areaCode, or could it have been any other attribute of phoneNumber, and it still would have performed the join?
    In my case, because the selection attributes are built up dynamicly, should I add all attributes of my child class (my equivalent PhoneNumber class)?

    Thanks for your reply Doug.
    One last question, hopefully.
    I have a parent table with 2 child tables. When attempting an outer join with both, toplink does not attempt to outer join either. I understand why, sort of - as you get an error when attempting this in sqlplus with "(+)" syntax.
    I understand that you can outer join > 1 other table to a parent with ansi sql syntax:
        select dept.*,emp.*
        from dept left outer join emp
        on dept.deptno = emp.deptnoWill toplink allow > 1 child table outer join to a parent table?

  • Can anyone tell me WHY Oracle won't allow sub-queries in outer joins?

    Hi,
    I've recently been tasked with converting a series of InterBase dbs to Oracle.
    Many of the queries in the InterBase dbs use sub-queries in outer joins. Oracle won't countenance this (01799 - a column may not be outer-joined to a subquery).
    I can get around it using functions but WHY won't Oracle allow this?
    SQL Server allows it, InterBase allows it (I don't know about ANSI SQL) but it seems to be a common enough technique...
    I'm just curious (and also a little frustrated!).
    Thanks in advance,,,

    Hi,
    >>Oracle treat an empty string as a NULL
    Well, you same answer your question. Because it is empty
    SGMS@ORACLE10> create table tab (cod number, name varchar2(1));
    Table created.
    SGMS@ORACLE10> insert into tab values (1,'');
    1 row created.
    SGMS@ORACLE10> insert into tab values (2,' ');
    1 row created.
    SGMS@ORACLE10> commit;
    SGMS@ORACLE10> select cod,dump(name) from tab;
           COD DUMP(NAME)
             1 NULL
             2 Typ=1 Len=1: 32
    SGMS@ORACLE10> select * from tab where name is null;
           COD NAME
             1Cheers
    If you talking about language tools, for example PHP treat empty string <> of NULL values. e.g: functions like is_empty() and is_null()
    Message was edited by:
    Legatti

  • Oute join

    How i can apply ANSI standared in i.e LEFT OUTER JOIN because in the query given below it's showing error
    SELECT NVL(uiq.question,ucq.question) as question,
    iqa.answer as answer,
    iqa.seperate_cover as reference_attached,
    iqa.attachment_extension as file_extension,
    iqa.filename as filename,
    addr.address_1 as attachment_address_1,
    addr.address_2 as attachment_address_2,
    addr.address_3 as attachment_address_3,
    addr.address_4 as attachment_address_4,
    addr.postcode as attachment_postcode,
    cty.description as attachment_country,
    iqa.upt_iqa_id as questionanswer.id
    FROM upt_iqa_questions_answers iqa,
    tpz_add_address addr,
    trf_cty_country cty,
    ukp_uiq_ins_question uiq,
    ukp_ucq_uic_question ucq
    WHERE iqa.upt_iap_id = <parameter primary key application>
    AND addr.tpz_add_id = iqa.tpz_add_id (+)
    AND cty.trf_cty_id = addr.trf_cty_id (+)
    AND uiq.ukp_uiq_id = iqa.ukp_uiq_id (+)
    AND ucq.ukp_ucq_id = iqa.ukp_ucq_id (+)
    ORDER BY iqa.position;

    Hello,
    I suppose that error message is ORA-01417 : a table may be outer joined to AT MOST ONE other table ?
    In this case, it means that you can not outer join iqa to addr, uiq and ucq.
    What is the meaning of your tables, and what data would you like to select ?

Maybe you are looking for