help with ansi joins

Hi all

I have this query in which I used ansi, not an expert but joins on joins ansi... had know abt joins ansi only today
SELECT abc.vendor_number, abc.vendor_name, api.invoice_amount,
       api.invoice_date, api.invoice_type_lookup_code, api.invoice_num,
       avp.prepay_number, api.description,   --,avp.INVOICE_CURRENCY_CODE CCY,
                                          aup.prepay_amount_applied,
       aup.prepay_amount_remaining,
       SUM (-avp.prepay_amount_remaining * NVL (api.exchange_rate, 1)
           ) prepaid_available,
       '1234' voucher_number
  FROM ap_invoices_v api INNER JOIN ap_invoice_distributions_v aid ON (    api.invoice_id =
                                                                              aid.invoice_id
                                                                       AND api.invoice_type_lookup_code =
                                                                              'PREPAYMENT'
                                                                       AND api.invoice_num =
                                                                              '5'
                                                                      ), ap_invoices_v api LEFT OUTER JOIN ap_apply_prepays_v avp ON (api.invoice_id =
                                                                                                                                         avp.invoice_id
                                                                                                                                     ),
       ap_invoices_v api INNER JOIN ap_checks_v abc ON (abc.vendor_id =
                                                                 api.vendor_id
                                                       ), ap_invoice_payments abb LEFT OUTER JOIN ap_apply_prepays_v avp ON (abb.invoice_id =
                                                                                                                                avp.invoice_id
                                                                                                                            ),
       ap_invoice_distributions_v aid LEFT OUTER JOIN ap_unapply_prepays_v aup ON (aid.invoice_distribution_id =
                                                                                      aup.prepay_distribution_id
                                                                                  ),
       ap_unapply_prepays_v aup LEFT OUTER JOIN ap_apply_prepays_v avp ON (aup.prepay_distribution_id =
                                                                              avp.invoice_distribution_id
                                                                          ), ap_invoices_v api INNER JOIN ap_invoice_payments abb ON (abb.invoice_id =
                                                                                                                                     api.invoice_id
                                                                                                                                 )
I'm ambigously column
defined in the select clause, is there another way to refer to the columns?

kindly Guide
thanking in advance

Published by: makdutakdu on December 20, 2011 11:28

Hello

SELECT abc.vendor_number,
    abc.vendor_name,
    api.invoice_amount,
    api.invoice_date,
    api.invoice_type_lookup_code,
    api.invoice_num,
    avp.prepay_number,
    api.description, --,avp.INVOICE_CURRENCY_CODE CCY,
    aup.prepay_amount_applied,
    aup.prepay_amount_remaining,
    SUM (-avp.prepay_amount_remaining * NVL (api.exchange_rate, 1) ) prepaid_available,
    '1234' voucher_number
FROM ap_invoices_v api
    INNER JOIN ap_invoice_distributions_v aid
    ON ( api.invoice_id              = aid.invoice_id
    AND api.invoice_type_lookup_code = 'PREPAYMENT'
    AND api.invoice_num              = '5' )
LEFT OUTER JOIN ap_apply_prepays_v avp
    ON (api.invoice_id = avp.invoice_id )
INNER JOIN ap_checks_v abc
    ON (abc.vendor_id = api.vendor_id)
INNER JOIN ap_invoice_payments abb
    ON (abb.invoice_id =api.invoice_id)
LEFT OUTER JOIN ap_apply_prepays_v avp
    ON (abb.invoice_id =avp.invoice_id)
LEFT OUTER JOIN ap_unapply_prepays_v aup
    ON (aid.invoice_distribution_id = aup.prepay_distribution_id),
LEFT OUTER JOIN ap_apply_prepays_v avp
    ON (aup.prepay_distribution_id =avp.invoice_distribution_id)

You join ap_apply_prepays_v three times, and you get the error, because you are still using the same alias.

However, this triple join is incorrect. Try

FROM    ap_invoices_v api
        JOIN ap_invoice_distributions_v aid
          ON (api.invoice_id = aid.invoice_id)
        JOIN ap_checks_v abc
          ON (abc.vendor_id = api.vendor_id)
        JOIN ap_invoice_payments abb
          ON (abc.check_id = abb.check_id
              AND abb.invoice_id = api.invoice_id)
        LEFT JOIN ap_unapply_prepays_v aup
          ON (aid.invoice_distribution_id = aup.prepay_distribution_id)
        LEFT JOIN ap_apply_prepays_v avp
          ON (api.invoice_id=avp.invoice_id
             AND aup.prepay_distribution_id = avp.invoice_distribution_id)
WHERE   api.invoice_type_lookup_code = 'PREPAYMENT'
AND     api.invoice_num = '5'

Concerning
Marcus

Tags: Database

Similar Questions

  • need help with outer join filter.

    Need a little help to filter a result set and I can't seem to find a good way to do this.
    /*table*/
    
    create table invoice( farinvc_invh_code varchar2(100),
                                  farinvc_item varchar2(100),
                                  farinvc_po varchar2(100)
                                  )
       create table po( 
            supplier_number varchar2(60),
            supplier_invoice_no varchar2(60),
            po_number varchar2(60),
            run_date varchar2(60),
            PO_LINE_NUMBER varchar2(60) );
    /*data*/
    
    INSERT INTO "INVOICE" (FARINVC_INVH_CODE, FARINVC_ITEM, FARINVC_PO_ITEM) VALUES ('I0554164', '1', 'P0142245');
    INSERT INTO "INVOICE" (FARINVC_INVH_CODE, FARINVC_ITEM, FARINVC_PO_ITEM) VALUES ('I0554164', '3', 'P0142245');
    INSERT INTO "INVOICE" (FARINVC_INVH_CODE, FARINVC_ITEM, FARINVC_PO) VALUES ('I0554165', '1', 'P0142246');
    INSERT INTO "INVOICE" (FARINVC_INVH_CODE, FARINVC_ITEM, FARINVC_PO) VALUES ('I0554165', '2', 'P0142246');
    
    
    
    
    
    INSERT INTO "PO" (SUPPLIER_NUMBER, SUPPLIER_INVOICE_NO, PO_NUMBER, RUN_DATE, PO_LINE_NUMBER) VALUES ('914100121', '529132260', 'P0142245', '21-NOV-12', '1');
    INSERT INTO "PO" (SUPPLIER_NUMBER, SUPPLIER_INVOICE_NO, PO_NUMBER, RUN_DATE, PO_LINE_NUMBER) VALUES ('914100121', '529137831', 'P0142245', '21-NOV-12', '3');
    INSERT INTO "PO" (SUPPLIER_NUMBER, SUPPLIER_INVOICE_NO, PO_NUMBER, RUN_DATE, PO_LINE_NUMBER) VALUES ('914100121', '529137831', 'P0142245', '21-NOV-12', '2');
    INSERT INTO "PO" (SUPPLIER_NUMBER, SUPPLIER_INVOICE_NO, PO_NUMBER, RUN_DATE, PO_LINE_NUMBER) VALUES ('914100122', '145678', 'P0142246', '22-NOV-12', '1');
    INSERT INTO "PO" (SUPPLIER_NUMBER, SUPPLIER_INVOICE_NO, PO_NUMBER, RUN_DATE, PO_LINE_NUMBER) VALUES ('914100122', '145679', 'P0142246', '22-NOV-12', '2');
    query execution of im.

    SELECT  farinvc_invh_code,
                    supplier_number,
                    supplier_invoice_no,
                    farinvc_item, 
                    farinvc_po ,
                    po_number,
                    run_date,
                    PO_LINE_NUMBER
            FROM INVOICE, PO
            WHERE PO_NUMBER = FARINVC_PO(+)
            AND FARINVC_ITEM(+) = PO_LINE_NUMBER
            
    result
    "FARINVC_INVH_CODE"           "SUPPLIER_NUMBER"             "SUPPLIER_INVOICE_NO"         "FARINVC_ITEM"                "FARINVC_PO"                  "PO_NUMBER"                   "RUN_DATE"                    "PO_LINE_NUMBER"              
    "I0554165"                    "914100122"                   "145678"                      "1"                           "P0142246"                    "P0142246"                    "22-NOV-12"                   "1"                           
    "I0554165"                    "914100122"                   "145679"                      "2"                           "P0142246"                    "P0142246"                    "22-NOV-12"                   "2"                           
    "I0554164"                    "914100121"                   "529132260"                   "1"                           "P0142245"                    "P0142245"                    "21-NOV-12"                   "1"                           
    "I0554164"                    "914100121"                   "529137831"                   "3"                           "P0142245"                    "P0142245"                    "21-NOV-12"                   "3"                           
    ""                            "914100121"                   "529137831"                   ""                            ""                            "P0142245"                    "21-NOV-12"                   "2"                           
    It is a much larger table, and I took an excerpt in order to keep things clear and understanding. I would like to filter the result set to only show lines that have po numbers are the same and line are the same but there is an additional element. in other words as such.
    "FARINVC_INVH_CODE"           "SUPPLIER_NUMBER"             "SUPPLIER_INVOICE_NO"         "FARINVC_ITEM"                "FARINVC_PO"                  "PO_NUMBER"                   "RUN_DATE"                    "PO_LINE_NUMBER"              
    "I0554164"                    "914100121"                   "529132260"                   "1"                           "P0142245"                    "P0142245"                    "21-NOV-12"                   "1"                           
    "I0554164"                    "914100121"                   "529137831"                   "3"                           "P0142245"                    "P0142245"                    "21-NOV-12"                   "3"                           
    ""                            "914100121"                   "529137831"                   ""                            ""                            "P0142245"                    "21-NOV-12"                   "2"                           

    Hello

    Let me assure you that I understand.
    Last time, we were looking for the PO_NUMBERs who have been partially put into correspondence , i.e. groups of rows in the order table with the same po_number, which some had corresponding lines in the table Bill, and some of whom have not. It was essential that there is at least 1 line and 1 row without connections with the same purchase order.
    Now that you are interested SUPPLIER_INVOICE_NOs who are partially paired, i.e. groups of rows in the table of po with the same po_number and supplier_invoice_no, some of which have corresponding lines in the invoice table, and some are not. ("Supplier_Invoice_No" is quite a mouthful. "We'll abbreviate as sin in the future.) However, the final selection is based on po_numbers: If a po_number has partially matched sins, then we are interested all po_number. For example, the result set must include = 529132260 SIN, even if that sin is completely, because there is a partially matching sin (529137831) with the same po_number (P0142245).

    As this problem revolves around partially matching sins, let's call them Cardinal sins . We can calculate match_cnt and total_cnt based NAS as well as po_number. Then, we can use another analytic function so see if the po_number has all cardinal_sins, like this:

    WITH    joined_data     AS
    (
         SELECT     i.farinvc_invh_code
         ,     p.supplier_number
         ,     p.supplier_invoice_no
         ,     i.farinvc_item
         ,     i.farinvc_po
         ,     p.po_number
         ,     p.run_date
         ,     p.po_line_number
         ,     COUNT (i.farinvc_po) OVER ( PARTITION BY  p.po_number
                                            ,                  p.supplier_invoice_no
                               )     AS match_cnt
         ,     COUNT (*)           OVER ( PARTITION BY  p.po_number
                                            ,                  p.supplier_invoice_no
                                          )     AS total_cnt
         FROM           po       p
         LEFT OUTER JOIN  invoice  i  ON   i.farinvc_po    = p.po_number
                                      AND  i.farinvc_item  = p.po_line_number
    )
    ,     got_cardinal_sin_cnt     AS
    (
         SELECT  joined_data.*
         ,     SUM ( CASE
                        WHEN  match_cnt  >= 1
                     AND     match_cnt  <  total_cnt
                     THEN  1
                    END
                  ) OVER (PARTITION BY  po_number)     AS cardinal_sin_cnt
         FROM    joined_data
    )
    SELECT    farinvc_invh_code
    ,       supplier_number
    ,       supplier_invoice_no
    ,       farinvc_item
    ,       farinvc_po
    ,       po_number
    ,       run_date
    ,       po_line_number
    FROM       got_cardinal_sin_cnt
    WHERE       cardinal_sin_cnt     > 0
    ORDER BY  po_number
    ,            farinvc_item
    ;
    
  • Need help with outer joins

    I have the following table structure,

    _ Table - 1
    ---------------------------------
    ID | Information
    ---------------------------------
    1. abcadskasasa
    2. asdasdasdasd
    3. saeqdfdvsfcsc
    ---------------------------------


    _ Table - 2
    ---------------------------------
    ID | NEST
    ---------------------------------
    1. 12
    1. 13
    2. 14
    1. 15
    1. 16
    2. 12
    ---------------------------------



    _ Table - 3
    ---------------------------------
    ID | THIERRY
    ---------------------------------
    1. 12
    2. 14
    1. 15
    ---------------------------------

    Now, I want to choose for each ID in table 1 and the number of MIP in the table 2-number of THIERRY of table 3.

    Desired output:_

    ---------------------------------------------------------------------------------------------------
    ID | COUNT_PID | COUNT_PARID
    ---------------------------------------------------------------------------------------------------
    1. 4. 2
    2. 2. 1
    3. 0 | 0
    ---------------------------------------------------------------------------------------------------

    Could someone please help me with this. I'm doing using outer joins, but as I work mainly at the edge of the end, not able to reach an appropriate solution to that above.

    Thanks in advance,
    Tejas

    You should not outer join... That should do it...

    select ID , (select count(PID) from table2  t2 where t2.id = t1.id) , (select count(PARID) from table3  t3 where t3.id = t1.id)
    from table1
    
  • Need help with the JOIN condition

    I have two tables tb1 and tb2. They join on two columns, namely, plan_name and activity_name. I must, however, ensure the following conditions by joining:

    1. pick up all the records that link between tb1 and tb2.

    2. If the tb1.plan_name is "Activity Adhoc" and then choose the lines that converge with tb2. Also pick up lines that do not join with tb2 where plan_name = 'Ad hoc activity'. For example:
    TB1 have 2 folders with plan_name Adhoc Acitivity
    plan_name activity_name
    Adhoc activity A1
    Adhoc activity A2
    TB2 has 1 plug with plan_name activity Adhoc
    plan_name activity_name
    Adhoc activity A1

    then the two records of tb1 should be taken. in other Assembly documents where plan_name <>"Adhoc Acitivity" should also be taken
    with tb1 as
    (
    select 'Adhoc Activity' plan_name,'A1' activity_name from dual union all
    select 'Adhoc Activity' plan_name,'A2' activity_name from dual union all
    select 'another Activity' plan_name,'A2' activity_name from  dual union all
    select 'Some another Activity' plan_name,'A2' activity_name from dual
    ),
    tb2 as
    (
    select 'Adhoc Activity' plan_name,'A1' activity_name from  dual union all
    --select 'Adhoc Activity' plan_name,'A2' activity_name dual union all
    select 'another Activity' plan_name,'A2' activity_name from  dual --union all
    --select 'Some another Activity' plan_name,'A2' activity_name dual
    )
    select *
    from(
       select a.plan_name a_plan_name,b.plan_name b_plan_name
       from tb1 a,tb2 b
       where a.plan_name = b.plan_name(+)
       and a.activity_name = b.activity_name(+)
         )
    where (a_plan_name = 'Adhoc Activity'  or b_plan_name is not null);
    
    A_PLAN_NAME           B_PLAN_NAME
    --------------------- ----------------
    Adhoc Activity        Adhoc Activity
    another Activity      another Activity
    Adhoc Activity                         
    

    Published by: JAC on November 19, 2012 10:27

  • Need help with outer join

    Hello

    I have a requirement in which I need to get data from a third table where a date of the third table is higher than a date in the second array.

    Ex:

    SELECT t1.column1, t3.column2
    FROM t1, t2, t3
    WHERE t1.id = t2.foreign_id
    AND t1.id ( + ) = t3.foreign_id
    AND t3.some_date_column > t2.another_date_column
    
    

    However, using the query above returns no results if the date condition is not met. I still need to show t1.column1 and a null t3.column2.

    How should I do this?

    Thank you

    Allen

    Edit: Added information about the requirement.

    Hi Allen

    1. SELECT t1.column1, t3.column2
    2. T1, t2, t3
    3. WHERE t1.id = t2.foreign_id
    4. AND t1.id = t3.foreign_id (+)
    5. AND t3.some_date_column (+) > t2.another_date_column

    I guess that this t1.column1 must not be null. Or am I wrong? The + sign must be placed on the side where draws are accepted. You must repeat it for each condition on the table.

    Alternativlely you can use the LEFT OUT JOIN syntax. If the two columns are allowed null you need a FULL OUTER JOIN.

    BTW: The join to t2 is not required if a refefernce constraint forced.

  • Help with Inner join problem

    The following query works fine as long as there is a value in the subID field, which is the end of the inner join statement. If the subID is empty then no data is output, even if it is there. Try as I may, I can't do the right solution in which the statement to get the data to show without the subID. What Miss me?

    < name cfquery = "getInfo" datasource = "#application.database #" >

    Select page_id, pageName, pages.content, pages.cat_id, pages.seo_title, pages.seo_desc, pages.seo_words, pages.h1_title, pages.pic, pages.brochure, pa ges.video, catagories.catagory, subcat.subID, subcat.sub_category

    (page INNER JOIN categories ON pages.cat_id = catagories.cat_id) INNER JOIN subcat ON pages.subID = subcat.subID

    where pages.page_id = #page_id #.

    < / cfquery >

    Rick,

    Looks like you need a LEFT OUTER join to the table "subcat", so that all the records for the 'pages' and 'categories' are returned, even if no records matching "subcat" doesn't exist.  Joins INTERNAL returns only the selected records when both sides of the join statement tables have matching values, while you will get a join OUTER LEFT (sometimes also known simply as a LEFT JOIN) * everything * selected records from the table on the left side of the join statement, no matter if he adapt records from the table on the right side of the join statement.  When there is no corresponding record in the table on the right side of the join statement, all the columns in your SELECT clause that come from the table on the right side of the join statement will contain NULL values.

    HTH,

    -Carl V.

  • Need clarification on the ANSI joins

    Hi all

    I need some clarification on the ANSI join I am building to avoid an error when I try to run the same in standard join.

    With standard join, I get the error ORA-01417: a table can be external joined as another table.

    Regular join condition:
    Select null
    Of
    land_event_device_fraud dealer update,-T1
    land_event_device_upgrade T2, - New Subscriber first Set
    syn_intg_event_device_state T3, - subscribed existing
    land_event_device_upgrade T4 - new Subscriber Second Set
    WHERE T1.event_id = T2.event_id (+) AND T1.rate_plan_id = T2.rate_plan_id (+)
    AND T1.event_id = T3.event_id (+) AND T1.rate_plan_id = T3.rate_plan_id (+)
    AND T4.event_id = T1.event_id (+) AND T4.event_id = T1.rate_plan_id (+)
    AND T4.event_id = T3.event_id (+) AND T4.event_id = T3.rate_plan_id (+);

    -Get the error ORA-01417.

    Replaced the join above with ANSI join

    SELECT NULL
    OF land_event_device_fraud t1
    LEFT OUTER JOIN t2 land_event_device_upgrade
    WE (t1.event_id = t2.event_id AND t1.rate_plan_id = t2.rate_plan_id)
    LEFT OUTER JOIN syn_intg_event_device_state t3
    WE (t1.event_id = t3.event_id AND t1.rate_plan_id = t3.rate_plan_id).
    land_event_device_upgrade t4
    LEFT OUTER JOIN land_event_device_fraud t5
    WE (t4.event_id = t5.event_id AND t4.rate_plan_id = t5.rate_plan_id)
    LEFT OUTER JOIN syn_intg_event_device_state t6
    WE (t4.event_id = t6.event_id AND t4.rate_plan_id = t6.rate_plan_id);


    I want to know if the ANSI join is goig work properly or it will give me any Cartesian production information.

    Appreciate your help here.

    Thank you
    MK.

    Hello

    Maldini says:
    Hi all

    I need some clarification on the ANSI join I am building to avoid an error when I try to run the same in standard join.

    With standard join, I get the error ORA-01417: a table can be external joined as another table.

    Regular join condition:
    Select null
    Of
    land_event_device_fraud dealer update,-T1
    land_event_device_upgrade T2, - New Subscriber first Set
    syn_intg_event_device_state T3, - subscribed existing
    land_event_device_upgrade T4 - new Subscriber Second Set
    WHERE T1.event_id = T2.event_id (+) AND T1.rate_plan_id = T2.rate_plan_id (+)
    AND T1.event_id = T3.event_id (+) AND T1.rate_plan_id = T3.rate_plan_id (+)
    AND T4.event_id = T1.event_id (+) AND T4.event_id = T1.rate_plan_id (+)
    AND T4.event_id = T3.event_id (+) AND T4.event_id = T3.rate_plan_id (+);

    -Get the error ORA-01417.

    Replaced the join above with ANSI join

    SELECT NULL
    OF land_event_device_fraud t1
    LEFT OUTER JOIN t2 land_event_device_upgrade
    WE (t1.event_id = t2.event_id AND t1.rate_plan_id = t2.rate_plan_id)
    LEFT OUTER JOIN syn_intg_event_device_state t3
    WE (t1.event_id = t3.event_id AND t1.rate_plan_id = t3.rate_plan_id).
    land_event_device_upgrade t4
    LEFT OUTER JOIN land_event_device_fraud t5
    WE (t4.event_id = t5.event_id AND t4.rate_plan_id = t5.rate_plan_id)
    LEFT OUTER JOIN syn_intg_event_device_state t6
    WE (t4.event_id = t6.event_id AND t4.rate_plan_id = t6.rate_plan_id);

    You mix ANSI joins and the old joints. It's very confusing. Use all of one type or the other.
    >

    I want to know if the ANSI join is goig work properly or it will give me any Cartesian production information.

    What happens when try you it? Is it produces the results you want?

    Whenever you have any questions, post a small example of data (CREATE TABLE and INSERT statements) and the results desired from these data. Explain how you get these results from these data.
    Always tell what version of oracle you are using.
    See the FAQ forum {message identifier: = 9360002}

    Why the SELECT clause includes only NULL? Is that going to serve as an EXISTS subquery? If so, why bother to make the outer joins, and why do you care if it is a Cartesian product? What is the query to go for?
    For the purposes of debugging, you can include something that you see in the SELECT clause.

  • Oracle vs ANSI joins

    Note a 'strange' behavior when you use ANSI joins in Oracle and I was wondering if there are still problems with their use in Oracle (11 g)

    Basically I have a MV_F_PRODUCT_ACTUAL vision, which is defined as a self-join to work the point in time for a product like the following values:
    SELECT
      F_PRODUCT_PREV.i_SK_Product,
      F_PRODUCT_PREV.i_SK_Version,
      F_PRODUCT_PREV.i_SK_VersionDate,
      D_CALENDAR.i_SK_Date AS i_SK_PointInTimeDate,
      F_PRODUCT_PREV.i_SK_Current,
      SUM(F_BOOKING.f_NoPax) AS f_NoPax
    FROM
      F_PRODUCT F_PRODUCT_PREV
    LEFT JOIN
      F_PRODUCT F_PRODUCT_NEXT
      ON
        F_PRODUCT_NEXT.i_SK_Product=F_PRODUCT_PREV.i_SK_Product
        AND
        F_PRODUCT_NEXT.i_SK_Version=F_PRODUCT_PREV.i_SK_Version+1
    LEFT JOIN
      D_CALENDAR
      ON
        D_CALENDAR.i_SK_Date BETWEEN F_PRODUCT_PREV.i_SK_VersionDate AND COALESCE(F_PRODUCT_NEXT.i_SK_VersionDate-1,TO_NUMBER(TO_CHAR(TRUNC(SYSDATE),'YYYYMMDD')))
    LEFT JOIN
      (
        SELECT
          F_BOOKING.i_SK_Product,
          F_BOOKING.i_SK_Bkg,
          D_CALENDAR.i_SK_Date AS i_SK_VersionDate,
          MAX(F_BOOKING.i_SK_Version) AS i_SK_BookingVersion
        FROM
          D_CALENDAR
        INNER JOIN
          F_BOOKING
          ON
            F_BOOKING.i_SK_VersionDate<=D_CALENDAR.i_SK_Date
        GROUP BY
          F_BOOKING.i_SK_Product,
          F_BOOKING.i_SK_Bkg,
          D_CALENDAR.i_SK_Date
      ) F_BOOKING_ON_DATE
      ON
        F_BOOKING_ON_DATE.i_SK_Product=F_PRODUCT_PREV.i_SK_Product
        AND
        F_BOOKING_ON_DATE.i_SK_VersionDate=D_CALENDAR.i_SK_Date
    LEFT JOIN
      F_BOOKING
      ON
        F_BOOKING.i_SK_Bkg=F_BOOKING_ON_DATE.i_SK_Bkg
        AND
        F_BOOKING.i_SK_Version=F_BOOKING_ON_DATE.i_SK_BookingVersion
    i.e. use ANSI joined to solve on the beaches of different dates between our F_BOOKING and F_PRODUCT tables. I cut the code from there as much as possible while retaining the main features.

    Now, if I question this view with ANSI joins as follows:
    SELECT 
      D_PRODUCT.A_PRODUCTCODE,
      D_PRODUCT.A_PRODUCTNAME,
      D_PRODUCT.A_PRODUCTTYPE,
      sum(NVL(MV_F_PRODUCT_ACTUAL.F_NOPAX,0)),
      sum(F_PRODUCT.F_ACTIVEPAXRANGE)
    FROM 
      MV_F_PRODUCT_ACTUAL
    LEFT JOIN
      D_PRODUCT
      ON
        D_PRODUCT.i_SK_Product=MV_F_PRODUCT_ACTUAL.i_SK_Product
    LEFT JOIN
      D_CALENDAR
      ON
        D_CALENDAR.i_SK_Date=MV_F_PRODUCT_ACTUAL.i_SK_PointInTimeDate
    LEFT JOIN
      F_PRODUCT
      ON
        F_PRODUCT.i_SK_Product=MV_F_PRODUCT_ACTUAL.i_SK_Product
        AND
        F_PRODUCT.i_SK_Version=MV_F_PRODUCT_ACTUAL.i_SK_Version
    WHERE 
      D_CALENDAR.Calendar_Date='01/Apr/2010'
    GROUP BY
      D_PRODUCT.A_PRODUCTCODE,
      D_PRODUCT.A_PRODUCTNAME,
      D_PRODUCT.A_PRODUCTTYPE;
    Then, the query returns results in less than a second. However, our report default application using joins in Oracle style as follows:
    SELECT
      D_PRODUCT.A_PRODUCTCODE,
      D_PRODUCT.A_PRODUCTNAME,
      D_PRODUCT.A_PRODUCTTYPE,
      sum(NVL(MV_F_PRODUCT_ACTUAL.F_NOPAX,0)),
      sum(F_PRODUCT.F_ACTIVEPAXRANGE)
    FROM
      D_PRODUCT,
      MV_F_PRODUCT_ACTUAL,
      F_PRODUCT,
      D_CALENDAR
    WHERE
      (
        D_PRODUCT.i_SK_Product=MV_F_PRODUCT_ACTUAL.i_SK_Product  
      )
        AND
      (
        D_CALENDAR.i_SK_Date=MV_F_PRODUCT_ACTUAL.i_SK_PointInTimeDate
      )
        AND
      (
        F_PRODUCT.i_SK_Product=MV_F_PRODUCT_ACTUAL.i_SK_Product
        AND
        F_PRODUCT.i_SK_Version=MV_F_PRODUCT_ACTUAL.i_SK_Version
      )
        AND
      (
        D_CALENDAR.Calendar_Date='01/Apr/2010'
      )
    GROUP BY
      D_PRODUCT.A_PRODUCTCODE,
      D_PRODUCT.A_PRODUCTNAME,
      D_PRODUCT.A_PRODUCTTYPE;
    And this query runs for hours without result.

    As far as I can tell, the two queries are functionally identical, so I left I was wondering if there is an additional optimization of the request being made by the first (ANSI at the bottom) query that is somehow not possible for the second syntax. Oracle would not 'smart' merge query in the view with the outer query in one case but not the other?

    I tried this create a materialized view (where the name), but the time to refresh an hour and a half is just too long to comfortably in our window of batch during the night. There are other optimizations of brute force, I could consider (staging of the motion of inline F_BOOKING_ON_DATE being the obvious one), but I'm afraid that if there is a fundamental incompatibility between the two join strategies that other similar problems can occur in our live environment without warning.

    Someone at - he had similar experiences?

    Published by: user11995414 on August 21, 2012 09:32

    As far as I can tell, the two motions are functionally identical,

    they are not.
    In ANSI variant it is LEFT JOIN in the Oracle variant, that I don't see

    (+)
    

    .

    Published by: user11181920 on August 21, 2012 14:44

  • Need help with the ANSI Join syntax

    Version: 11.1.0.7

    I have my select statement that returns 3000 lines and looks like
    select ..
    from tab1 a,tab2 b,tab3 c
    where a.c1=b.c1 and
    b.c2 = c.c2(+)
    and ...
    group by
    ..
    I want to convert it to ANSI SQL, because it must be able to Hibernate, and the developer says that Hibernate include only ANSI SQL. I tried something like
    select ..
    from tab1 a INNER JOIN tab2 b
    ON a.c1=b.c1 
    LEFT OUTER JOIN tab3 c
    ON b.c2=c.c2
    where ...
    group by
    ..
    I felt bad and it turned out to be the same. It returns no rows. Please help with the correct syntax.

    I'm not sure, sorry, because it's certainly the ANSI equivalent to the non-ANSI.

    Would you have examples of queries and data that you can reproduce the problem with, and that we could analyze?

    Published by: Seanmacgc on July 15, 2009 12:48

    If there is no Clause WHERE conditions in the original that are included in the ANSI version of the query in the WHERE Clause for the EXTERNAL table itself joined, then that could transform the JOIN JOIN internally, that is, all the filters on the EXTERNAL joined table should be included in the JOIN predicate - IT (b.c2 = c.2 AND c.c3 = 'X').

  • Problem with ANSI OUTER JOIN

    Hi all

    I have issues with the help of ANSI LEFT JOIN compared to Oracle (+). Below test I did the same thing.
          create table emp (emp_id number(10), emp_name varchar2(50));
          create table courses (course_id number(10), emp_id number(10), course_name varchar2(50));
          
          INSERT INTO EMP values(1,'A');
          INSERT INTO EMP values(2,'B');
          INSERT INTO EMP values(3,'C');
    
          INSERT INTO COURSES values(1,1,'ORACLE');
          INSERT INTO COURSES values(2,1,'JAVA');
          INSERT INTO COURSES values(3,3,'C#');
    
          --*Query 1
          SELECT a.*, b.*
          FROM EMP a  LEFT JOIN COURSES b 
          ON a.emp_id = b.emp_id
          AND a.emp_name = 'A'
    
          --*Query 2      
          SELECT a.*, b.* 
          FROM EMP a, COURSES b 
          where a.emp_id = b.emp_id(+)
          and a.emp_name = 'A'
    Here Query1 return all records of 4 same records regardless of emp_name = 'A' where as Query2 returns 2 records of ep_name = 'A' which is correct.

    Is this correct? I'm confused if you use the standard ANSI OUTER JOINS or not.

    I am using Oracle 11g

    Thank you.

    Change your AND WHERE, in the style of ANSI, select:

    SELECT a.*, b.*
    FROM EMP a  LEFT JOIN COURSES b
    ON a.emp_id = b.emp_id
    WHERE a.emp_name = 'A'
    

    Filters in the clause are those who use the (+) in the Oracle syntax.
    Filters WITHOUT (+) in the Oracle syntax should be in the WHERE clause using the ANSI syntax.

    Published by: Kim Berg Hansen on September 23, 2011 08:03

  • help on SQL JOIN Conversion of ANSI STANDARD

    SELECT Q.FLDQUESTION, Q.FLDCMNTPRMT, Q.FLDISHEAD, Q.FLDCODE, M.FLDDATA, A.FLDYESNO, C.FLDDATA
    OF CANQSTN Q,.
    LOGCAANS, A.
    CANQSTN_MEMO M.
    C LOGCAANS_MEMO
    WHERE A.FLDCASE =? AND
    Q.FLDCODE = A.FLDQUESTION AND
    Q.FLDPOSSCACT * = M.FLDREC_NUM (+) AND
    A.FLDCOMMENT * = C.FLDREC_NUM (+)
    ORDER BY A.FLDSEQUENCE

    This request must be converted to ANSI Standard SQL JOIN.

    SELECT Q.FLDQUESTION, Q.FLDCMNTPRMT, Q.FLDISHEAD, Q.FLDCODE, M.FLDDATA, A.FLDYESNO, C.FLDDATA
    OF (inner CANQSTN Q join A LOGCAANS on Q.FLDCODE = A.FLDQUESTION)
    LEFT OUTER JOIN CANQSTN_MEMO M ON Q.FLDPOSSCACT = M.FLDREC_NUM
    Here, I stuck with join remaining 2 tables A.FLDCOMMENT * = C.FLDREC_NUM (+)
    could you any body please help me on this query.

    JOURNAL OF LOGCAANS, CANQSTN TABLES REFERENCES.

    Hello, here is the equivalent ANSI JOIN:

    SELECT Q.FLDQUESTION, Q.FLDCMNTPRMT, Q.FLDISHEAD, Q.FLDCODE,
         M.FLDDATA, A.FLDYESNO, C.FLDDATA
      FROM CANQSTN Q
      JOIN LOGCAANS ON (Q.FLDCODE = A.FLDQUESTION)
      LEFT JOIN CANQSTN_MEMO M ON (Q.FLDPOSSCACT = M.FLDREC_NUM)
      LEFT JOIN LOGCAANS_MEMO C ON (A.FLDCOMMENT = C.FLDREC_NUM)
     WHERE A.FLDCASE = ?
     ORDER BY A.FLDSEQUENCE;
    
  • Need help with joins Oracle


    Hi all

    Any new on Oracle Sql and I need expert input to solve a problem I have to join Oracle.

    Have a requirement as below, my reading of request as below.

    SELECT A.GCI, B.LOB_IND, B.CED_ID, C. LOB_DESCR OF CUSTOMER, CUSTOMER b, C from LOB

    WHERE A.PRIMARY_CED = B.CED_ID (+)

    AND B.LOB = C.LOB_DESCR (+)

    AND B.LOB_IND (+) = 'Y '.

    AND A.GCI IN

    (

    '339492963',

    '339850821');

    Output current:

    GCI LOB_IND CED_ID LOB_DESCR

    339850821 Y 7905108 banking services for businesses

    Null Null null 339492963

    Power required:

    GCI LOB_IND CED_ID LOB_DESCR

    339850821 Y 7905108 banking services for businesses

    339492963 7859659 null null

    In the table B (CLIENT) for a ced_id there will be several entries.

    Select ced_id, LOB_IND from CLIENT b where b.ced_id = '7905108';

    ced_id LOB_IND

    7905108 IS

    7905108 null

    7905108 null

    Select ced_id, LOB_IND from CLIENT b where b.ced_id = 7859659;

    ced_id LOB_IND

    7859659 null

    7859659 null

    so when writing of the main request, I took B.LOB_IND (+) = 'Y' condition, since I added this condition and catches of outer join.

    the ced_id for "7859659" is not coming in the query below.

    SELECT A.GCI, B.LOB_IND, B.CED_ID, C. LOB_DESCR OF CUSTOMER, CUSTOMER b, C from LOB

    WHERE A.PRIMARY_CED = B.CED_ID (+)

    AND B.LOB = C.LOB_DESCR (+)

    AND B.LOB_IND (+) = 'Y '.

    AND A.GCI IN

    (

    '339492963',

    '339850821');

    Output current:

    GCI LOB_IND CED_ID LOB_DESCR

    339850821 Y 7905108 banking services for businesses

    Null Null null 339492963

    Is it possible that the query can be modified to get the below output with CED_ID for B.LOB_IND-> case of Null.

    Power required:

    GCI LOB_IND LOB LOB_DESCR

    339850821 Y 7905108 banking services for businesses

    339492963 7859659

    Your entered very necessary.

    Thank you

    Be great if someone could have provide some suggestions.

    Use ANSI joins:

    SELECT A.GCI, B.LOB_IND,
    B.CED_ID,
    C.LOB_DESCR
    CUSTOMER A
    LEFT JOIN
    CLIENT b, C from LOB
    ON)
    A.GCI IN)
    '339492963',
    '339850821'
    )
    AND
    A.PRIMARY_CED = B.CED_ID
    AND
    B.LOB_IND = 'Y '.
    )
    LEFT JOIN
    C LOB
    ON)
    B.LOB = C.LOB_DESCR
    )
    /

    SY.

  • Need help with the condition join in SQL

    Hi all -

    I need to ask for help with this query:

    Create table user_tab_col_test (varchar2 (30) from table_name, column_name varchar2 (30), data_type varchar2 (30));

    Insert into user_tab_col_test (table_name, column_name, data_type) values ('table1', 'column1', 'varchar2')
    Insert into user_tab_col_test (table_name, column_name, data_type) values ('Column2', 'table1', 'varchar2')
    Insert into user_tab_col_test (table_name, column_name, data_type) values ("Column3", 'table1', 'varchar2')
    Insert into user_tab_col_test (table_name, column_name, data_type) values ('column4', 'table1', 'varchar2')
    Insert into user_tab_col_test (table_name, column_name, data_type) values ("column1", "table2", 'varchar2')
    Insert into user_tab_col_test (table_name, column_name, data_type) values ('table2', 'column2', 'varchar2')
    Insert into user_tab_col_test (table_name, column_name, data_type) values ('table2', "Column3", 'varchar2')
    Insert into user_tab_col_test (table_name, column_name, data_type) values ('table2', 'column4', 'varchar2')
    Commit;

    Create table all_cons_columns_test (varchar2 (30) from table_name, column_name varchar2 (30), constraint_name varchar2 (30))

    Insert into all_cons_columns_test (table_name, column_name, constraint_name) values ("table1", "column1", "primary")
    Insert into all_cons_columns_test (table_name, column_name, constraint_name) values ("table1", "column1", "secondary")
    Commit;

    This is my query and the current result:

    Select u.table_name, u.column_name, c.constraint_name
    Of user_tab_col_test u
    Outer join all_cons_columns_test c left
    On (u.table_name = c.table_name
    AND U.COLUMN_NAME = C.COLUMN_NAME
    AND C.CONSTRAINT_NAME IN ('main'))
    order of U.table_name, U.COLUMN_NAME;

    TABLE_NAME COLUMN_NAME, CONSTRAINT_NAME
    ------------------ --------------------- ----------------------------
    Table1 primary Column1
    Table1 Column2
    Table 1 Column3
    Table2 Column1
    Table2 Column2


    Three questions:
    (1) I don't want to return results where table_name = "table1". I can't get this to work.
    (2) is my proper request and this is the best way to return my desired results? For example, I want all of the columns of user_tab_col_test and I want to only display the constraint_name from all_cons_columns_test argument if the argument constraint_name = 'primary '.
    (3) will be the synatx be the same if I need to join a third table to all_cons_columns_test?

    Any advice/suggestions are appreciated-
    John

    Published by: user703358 on January 11, 2013 20:57

    Published by: user703358 on January 11, 2013 21:48

    Hi, John,.

    user703358 wrote:
    Hi all -

    I need to ask for help with this query:

    Create table user_tab_col_test (varchar2 (30) from table_name, column_name varchar2 (30), data_type varchar2 (30));

    Insert into user_tab_col_test (table_name, column_name, data_type) values ('table1', 'column1', 'varchar2')
    Insert into user_tab_col_test (table_name, column_name, data_type) values ('Column2', 'table1', 'varchar2')...

    Thanks for posting the CREATE TABLE and INSERT.
    It is more useful if you post the code that can be run without modification. You did not semicolons after INSERTION instructions.

    Three questions:
    (1) I don't want to return results where table_name = "table1". I can't get this to work.

    What have you tried? Post your best attempt.
    Here's one way:

    SELECT    u.table_name
    ,        u.column_name
    ,        c.constraint_name
    FROM             user_tab_col_test      u
    LEFT OUTER JOIN  all_cons_columns_test  c
                            ON    u.table_name     = c.table_name
                   AND   u.column_name     = c.column_name
                   AND   c.constraint_name IN ('primary')
    WHERE       u.table_name     = 'table1'          --  *****  NEW  *****
    ORDER BY  u.table_name
    ,            u.column_name
    ;
    

    You would not put this condition in the clause; who controls what is considered as a match between the tables, and "u LEFT OUTER JOIN c" means show all lines of u, even if they do not have a match in the c.

    (2) is my proper request and this is the best way to return my desired results? For example, I want all of the columns of user_tab_col_test and I want to only display the constraint_name from all_cons_columns_test argument if the argument constraint_name = 'primary '.

    Basically, this application is very well.
    It displays all the columns of user_tab_col_test; missing data_type. Just add u.data_type to the SELECT clause, or change the SELECT clause

    SELECT    u.*
    ,         c.constraint_name
    

    (3) will be the synatx be the same if I need to join a third table to all_cons_columns_test?

    Do you mean "" * add * one-third * column * to all_cons_columns_test '? "
    It depends on what results you want. Post new CREATE TABLE and INSERT and instructions the results you want new data.
    Most likely, the basic structure of what you've written will remain exactly the same.

  • old script with joins instead of ansi joins

    In 9i OWB when I generate the intermediate result script, it is generateing join in the OLD style as conditions below.
    a.ID = b.id (+)

    But in Oracle 11 g, it raises the join conditions in the Ansi joins as below
    a left outer join b on (a.id = b.id)


    Is there a way to generate the intermediate result script in an old style in OWB 11 g?

    Help, please.

    I did a quick post here showing ownership.
    https://blogs.Oracle.com/warehousebuilder/entry/owb_ansi_and_oracle_sql

    See you soon
    David

  • Need help with join

    I have a problem with the join, I try to use it to eliminate the mass number of path layers and sublayers I. Everything is already connected by anchor point but they have all of the separate layers and it is heavy for shipping and export.

    Here's what I want to join, lines are in place and, even once, the anchor points are connected. I want to keep this form:

    Untitled.jpg

    And that's what he keeps to:

    Untitled 2.jpg

    Any suggestion is welcome.

    dmuir,

    You can reach only two segments of track at the same time, so that each (no end) Anchor Point has only two adjacent segments.

    You can combine paths and creating paths compound and other things, but you're stuck with a number of roads as building blocks.

Maybe you are looking for

  • Cannot synchronize my iOS iphone 6 10 12.5.1.21 iTunes for windows

    12.5.1.21 iTunes for Windows 10 64 bit does not recognize my iphone 6 iOS10. I followed the steps in the apple support... went to the Device Manager and less "universal Bus USB controllers" there NO Apple Mobile Device USB Driver.

  • Skype Call Failed: The problem with the recording device.

    Well, whenever I try Skype call my friends, or even the test thing, he always falls the appeal and there is a yellow popup at the top that says: "Proem with recording device"... Including"[17: 07:01] * call to Echo / Sound Test Service, no response.

  • build LV2010 Installer error

    Hello I use LV2010 32 bit, vision tools, database tools, Win7 64-bit. I get the following error when I Isaiah to compile a Setup program.  The executable file is based without any problem only the installation program: CodeSignAPI.lvlib:Get signature

  • computer - cannot change to Classic view problems

    original title: computer problems Hi my computer is going crazy all of a sudden that my Start menu seems to have changed to Classic view by its self. Then when I tried to change back to normal look, he's not here. I keep all of my updates to day and

  • two hard drives, one with vista and the other with XP and you want to remove second disk XP

    I have a hard drive that came with my computer and vista on it, I added a second drive to my bench that has XP on it. I want to remove the second XP disc and simply use it as a storage drive, and I'm afraid that if I try and uninstall XP disc, it all