Left join to another database

Hello
I had a scenario where I need to write a query that gets SQL Server database records, but have a left join on Oracle table, I know we can achiev this link between Oracle and SQL DB, but my team of DB are unwilling to create links from DB, is there a way probably from data models We can write a query that can call Oracle table too?

Here is an article from blog of tim on the subject:

http://blogs.Oracle.com/XmlPublisher/2008/07/multiple_datasources_i.html

Tags: Business Intelligence

Similar Questions

  • Left Join with a subquery

    Hey everybody!

    I have some difficulty in trying to create a SQL query.

    I have the following tables:

    -Table Products: Product list
    CREATE TABLE (PRODUCTS)
    PRODUCT_ID INTEGER NOT NULL,
    KEY ("PRODUCT_ID") PRIMARY CONSTRAINT 'PK_PRODUCTS '.
    );

    -Orders table: Decreed this product
    CREATE TABLE ORDERS)
    ORDER_ID INTEGER NOT NULL,
    PRODUCT_ID INTEGER NOT NULL, / * FK PRODUCTS (PRODUCT_ID) * /.
    KEY ("ID_PEDIDO") PRIMARY CONSTRAINT 'PK_ORDERS '.
    );

    -Orders_Approval table: register when an order is approved
    CREATE TABLE ORDERS_APPROVAL)
    ORDER_ID INTEGER NOT NULL, / * FK ORDERS (ORDER_ID) * /.
    APPROVAL_DATE DATE NOT NULL,
    USER_ID INTEGER,
    KEY("ORDER_ID","APPROVAL_DATE") PRIMARY CONSTRAINT 'PK_ORDERS_APPROVAL '.
    );

    -Table Orders_ApprovalData: Register more details on the amenities of the order
    CREATE TABLE ORDERS_APPROVAL_DETAILS)
    APPROVALDET_ID INTEGER NOT NULL,
    ORDER_ID INTEGER NOT NULL, / * FK ORDERS_APPROVAL (ORDER_ID) * /.
    APPROVAL_DATE DATE NOT NULL, / * FK ORDERS_APPROVAL (APPROVAL_DATE) * /.
    KEY ("APPROVALDET_ID") PRIMARY CONSTRAINT 'PK_ORDERS_APPROVAL_DETAILS '.
    );

    The thing is that an order may OU cannot be approved. Thus, there could be no record of an order in ORDERS_APPROVAL.

    In addition, an order can have more than one approval.

    Here is the data that I use:

    /===========\
    | PRODUCTS |
    |===========|
    | PRODUCT_ID |
    |===========|
    | 1.
    |===========|
    | 2.
    |===========|
    | 3.
    \===========/

    /========================\
    | ORDERS |
    |========================|
    | ORDER_ID | PRODUCT_ID |
    |===========|============|
    | 27. 1.
    |===========|============|
    | 28. 2.
    |===========|============|
    | 29. 3.
    \===========|============/

    /=========================================\
    | ORDERS_APPROVAL |
    |=========================================|
    | ORDER_ID | APPROVAL_DATE | USER_ID.
    |===========|================|============|
    | 27. 01/10/2009 | 56.
    |===========|================|============|
    | 27. 04/10/2009 | 96.
    |===========|================|============|
    | 29. 03/10/2009 | 77.
    \===========|================|============/

    /=============================================\
    | ORDERS_APPROVAL_DETAILS |
    |=============================================|
    | APPROVALDET_ID | ORDER_ID | APPROVAL_DATE |
    |================|===========|================|
    | 1. 27. 01/10/2009 |
    |================|===========|================|
    | 2. 27. 04/10/2009 |
    |================|===========|================|
    | 3. 29. 03/10/2009 |
    \================|===========|================/
    I need to create a query that returns the data in all tables, but for orders with more than one certification,
    the query must return only the last record. It is also necessary return orders that have not yet been approved.

    My first query looked like this:

    SELECT
    *
    Of
    ORD IN ORDERS,
    PRODUCT PROD,
    ORDERS_APPROVAL ORDAPPROV,
    ORDERS_APPROVAL_DETAILS ORDAPPDET
    WHERE
    PROD. PRODUCT_ID = DSB. PRODUCT_ID
    AND ORDAPPROV. ORDER_ID (+) IS DSB. ORDER_ID
    AND ORDAPPDET. ORDER_ID (+) IS ORDAPPROV. ORDER_ID
    AND ORDAPPDET. DATA_APPROVAL_DATE (+) IS ORDAPPROV. APPROVAL_DATE

    PS: I use the Oracle 8 syntax because it's the server I'll use. In addition, I can't change the design of database.

    This query returns the data in table all. Because I used LEFT JOIN "(+)" to join the table orders_approval with the orders table, I am able to see even the orders with no approval.

    But this way, I see also two approvals for order 27 (with the data above, this order was approved twice). I need to reach my paintings in the last approval for each order is but should be a left join so I can see the orders with no approval.

    I tried this way:

    SELECT
    *
    Of
    ORD IN ORDERS,
    PRODUCT PROD,
    ORDERS_APPROVAL ORDAPPROV,
    ORDERS_APPROVAL_DETAILS ORDAPPDET
    WHERE
    PROD. PRODUCT_ID = DSB. PRODUCT_ID
    AND ORDAPPROV. ORDER_ID (+) IS DSB. ORDER_ID
    --Also added the line below
    AND ORDAPPROV. APPROVAL_DATE = (SELECT MAX (APPROVAL_DATE) OF ORDERS_APPROVAL WHERE THE ORDER_ID = ORDAPPROV. ORDER_ID)
    AND ORDAPPDET. ORDER_ID (+) IS ORDAPPROV. ORDER_ID
    AND ORDAPPDET. DATA_APPROVAL_DATE (+) IS ORDAPPROV. APPROVAL_DATE

    But in this way, as I am specifying I want only records with approval equal to date at the latest for each order, I do not see the order without approval.

    I tried again, with a left join like this:

    SELECT
    *
    Of
    ORD IN ORDERS,
    PRODUCT PROD,
    ORDERS_APPROVAL ORDAPPROV,
    ORDERS_APPROVAL_DETAILS ORDAPPDET
    WHERE
    PROD. PRODUCT_ID = DSB. PRODUCT_ID
    AND ORDAPPROV. ORDER_ID (+) IS DSB. ORDER_ID
    --Also added the line below
    AND ORDAPPROV. APPROVAL_DATE (+) = (SELECT MAX (APPROVAL_DATE) OF ORDERS_APPROVAL WHERE THE ORDER_ID = ORDAPPROV. ORDER_ID)
    AND ORDAPPDET. ORDER_ID (+) IS ORDAPPROV. ORDER_ID
    AND ORDAPPDET. DATA_APPROVAL_DATE (+) IS ORDAPPROV. APPROVAL_DATE

    But I get a syntax error. Oracle said that it is not possible to do a join with a subquery.

    If anyone knows how I can bring all this data?

    Thanks in advance.

    Published by: user9936895 on 05/10/2009 09:42: tried to fix the predetermined data schema.

    Hello

    Welcome to the forum!

    A scalar, such as subquery

    (SELECT MAX(APPROVAL_DATE) FROM ORDERS_APPROVAL WHERE ORDER_ID=ORDAPPROV.ORDER_ID)
    

    is allowed in a WHERE clause, but not as a condition of outer join, as you discovered.

    A workaround is the query expression so that it is not part of the outer join condition, which invlove in May (as in this case), adding another subquery. In the following query, the table of orders_approval in your original OF Division is replaced with online view, which uses the exact same scalar subquery in the WHERE clause. The online display will only contain one line per order_id (assuming that there is no link with for last approval_date).

    SELECT
         *
    FROM
         orders               ord,
         products          prod,
         (     -- Begin in-line view ORDAPPROV of last approval_date only
         SELECT     *       -- or list the columns needed in main query
         FROM     orders_approval         oa
         WHERE     approval_date = (
                        SELECT  MAX (approval_date)
                        FROM     orders_approval
                        WHERE     order_id     = oa.order_id
                        )
         )                ordapprov,
         orders_approval_details ordappdet
    WHERE
         prod.product_id               = ord.product_id
    AND     ordapprov.order_id (+)          = ord.order_id
    AND     ordappdet.order_id (+)          = ordapprov.order_id
    AND     ordappdet.approval_date (+)     = ordapprov.approval_date
    ;
    

    Thank you for including CREATE TBAL statements; It is very useful.
    You want to be even more useful in the future? Post INSERT statements for the sample data. That will make it easier for people to respond and easier for them to test their ideas.

  • Clarification on NULL or behavior LEFT JOIN behavior

    Good day ladies------Gentlemen\ gurus-Experts-and Al:

    Just when I thought I got my mind wrapped around the notion of NULL value, as defined by Oracle, I met what follows below.  Basically, what you are watching is how our employees of the human resources tables are set up (for the most part).  We have the employees, employee contracts table and the tables of positions.  When I want to make a list of active staff, I always use the filter end date, you will see below in the Super request, essentially looking for staff who do not have a contract AND a position end date entered in the DB.  It works like a charm.  However, today, I noticed an official on the list, who has never had a position is entered in the comic book, and he had an 'open' contract  In my example below, why would "Hal Jordan" appear on the active staff list?  Yes, he spends the first part of my predicate (contract_end is null), but it does not work (at least by my understanding) past the second part of the predicate which is position_end has the value NULL because there not even a record is entered in the comics!  Why would he appear?  Is it because of the LEFT JOIN or a NULL rule type, I'm not aware of?  Thanks for your help!

    Aqua

    EMPLOYEES AS

    (

    SELECT '10' AS emp_id, 'Banner' last_name, 'Robert' NAME FROM dual

    UNION ALL

    SELECT '20', 'Wayne', 'Bruce' OF THE double

    UNION ALL

    SELECT '30', 'Kent', 'Clark' FROM dual

    UNION ALL

    SELECT "40", "Parker", "Peter" OF THE double

    UNION ALL

    SELECT '50', 'Last', 'Tony' FROM dual

    UNION ALL

    SELECT '60', 'Jordan', 'Hal' OF THE double

    ),

    emp_contracts AS

    (

    SELECT '10' AS emp_id, to_date (January 1, 2011 ',' MON-DD-YYYY "") LIKE contract_start, to_date (1 January 2012 ',' MON-DD-YYYY') AS contract_end FROM dual

    UNION ALL

    To_date '10', SELECT (January 1, 2010 ',' MON-DD-YYYY ""), to_date (December 31, 2011 ',' MON-DD-YYYY') OF double

    UNION ALL

    To_date '10', SELECT (January 2, 2012 ',' MON-DD-YYYY ""), double NULL

    UNION ALL

    To_date '20', SELECT (January 1, 2011 ',' MON-DD-YYYY ""), to_date (1 January 2012 ',' MON-DD-YYYY') OF double

    UNION ALL

    To_date '20', SELECT (January 1, 2010 ',' MON-DD-YYYY ""), to_date (December 31, 2011 ',' MON-DD-YYYY') OF double

    UNION ALL

    To_date '20', SELECT (January 2, 2012 ',' MON-DD-YYYY ""), double NULL

    UNION ALL

    To_date '30', SELECT (January 1, 2011 ',' MON-DD-YYYY ""), to_date (1 January 2012 ',' MON-DD-YYYY') OF double

    UNION ALL

    To_date '30', SELECT (January 1, 2010 ',' MON-DD-YYYY ""), to_date (December 31, 2011 ',' MON-DD-YYYY') OF double

    UNION ALL

    To_date '30', SELECT (January 2, 2012 ',' MON-DD-YYYY ""), double NULL

    UNION ALL

    To_date '40', SELECT (January 1, 2011 ',' MON-DD-YYYY'), to_date (1 January 2012 ',' MON-DD-YYYY') FROM dual

    UNION ALL

    To_date '40', SELECT (January 1, 2010 ',' MON-DD-YYYY'), to_date (December 31, 2011 ',' MON-DD-YYYY') FROM dual

    UNION ALL

    To_date '40', SELECT (January 2, 2012 ',' MON-DD-YYYY ""), double NULL

    UNION ALL

    To_date '50', SELECT (January 1, 2011 ',' MON-DD-YYYY ""), to_date (1 January 2012 ',' MON-DD-YYYY') OF double

    UNION ALL

    To_date '50', SELECT (January 1, 2010 ',' MON-DD-YYYY ""), to_date (December 31, 2011 ',' MON-DD-YYYY') OF double

    UNION ALL

    To_date '50', SELECT (January 2, 2012 ',' MON-DD-YYYY ""), double NULL

    UNION ALL

    To_date '60', SELECT (January 1, 2011 ',' MON-DD-YYYY ""), to_date (1 January 2012 ',' MON-DD-YYYY') OF double

    UNION ALL

    To_date '60', SELECT (January 1, 2010 ',' MON-DD-YYYY ""), to_date (December 31, 2011 ',' MON-DD-YYYY') OF double

    UNION ALL

    To_date '60', SELECT (January 2, 2012 ',' MON-DD-YYYY ""), double NULL

    ),

    emp_positions AS

    (

    SELECT '10' AS emp_id, '43XY' AS title_id, to_date (January 1, 2011 ',' MON-DD-YYYY "") LIKE position_start, to_date (1 January 2012 ',' MON-DD-YYYY') AS position_end FROM dual

    UNION ALL

    SELECT ' 10', '47NT', to_date (January 1, 2010 ',' MON-DD-YYYY ""), to_date (December 31, 2011 ',' MON-DD-YYYY') OF double

    UNION ALL

    SELECT ' 10', '41JE', to_date (January 2, 2012 ',' MON-DD-YYYY ""), double NULL

    UNION ALL

    SELECT ' 20', '48AW', to_date (January 1, 2011 ',' MON-DD-YYYY ""), to_date (1 January 2012 ',' MON-DD-YYYY') OF double

    UNION ALL

    SELECT ' 20', '42KD', to_date (January 1, 2010 ',' MON-DD-YYYY ""), to_date (December 31, 2011 ',' MON-DD-YYYY') OF double

    UNION ALL

    SELECT ' 20', '46LD', to_date (January 2, 2012 ',' MON-DD-YYYY ""), double NULL

    UNION ALL

    SELECT ' 30 ', 45 MI', to_date (January 1, 2011 ',' MON-DD-YYYY'), to_date (1 January 2012 ',' MON-DD-YYYY') FROM dual

    UNION ALL

    SELECT ' 30', '44KH', to_date (January 1, 2010 ',' MON-DD-YYYY ""), to_date (December 31, 2011 ',' MON-DD-YYYY') OF double

    UNION ALL

    SELECT ' 30', '43LL', to_date (January 2, 2012 ',' MON-DD-YYYY ""), double NULL

    UNION ALL

    SELECT ' 40', '41', to_date (January 1, 2011 ',' MON-DD-YYYY ""), to_date (1 January 2012 ',' MON-DD-YYYY') OF double

    UNION ALL

    SELECT ' 40', '40', to_date (January 1, 2010 ',' MON-DD-YYYY ""), to_date (December 31, 2011 ',' MON-DD-YYYY') OF double

    UNION ALL

    SELECT ' 40', '42DX', to_date (January 2, 2012 ',' MON-DD-YYYY ""), double NULL

    UNION ALL

    SELECT ' 50', '48IB', to_date (January 1, 2011 ',' MON-DD-YYYY ""), to_date (1 January 2012 ',' MON-DD-YYYY') OF double

    UNION ALL

    SELECT '50 ', 47 DL', to_date (January 1, 2010 ',' MON-DD-YYYY'), to_date (December 31, 2011 ',' MON-DD-YYYY') FROM dual

    UNION ALL

    SELECT ' 50', '42A', to_date (January 2, 2012 ',' MON-DD-YYYY ""), double NULL

    )

    SELECT

    1. ES.emp_id,
    2. ES.last_name,
    3. ES.first_name,
    4. EP.title_id,
    5. EP.position_start,
    6. EP.position_end

    Employees are

    LEFT JOIN emp_contracts ec

    ON ec.emp_id = es.first_name

    LEFT JOIN emp_positions ep

    ON ep.emp_id = es.emp_id

    WHERE ec.contract_end IS NULL AND ep.position_end IS NULL

    Hello

    AquaNX4 wrote:

    Good day ladies------Gentlemen\ gurus-Experts-and Al:

    Just when I thought I got my mind wrapped around the notion of NULL value, as defined by Oracle, I met what follows below.  Basically, what you are watching is how our employees of the human resources tables are set up (for the most part).  We have the employees, employee contracts table and the tables of positions.  When I want to make a list of active staff, I always use the filter end date, you will see below in the Super request, essentially looking for staff who do not have a contract AND a position end date entered in the DB.  It works like a charm.  However, today, I noticed an official on the list, who has never had a position is entered in the comic book, and he had an 'open' contract  In my example below, why would "Hal Jordan" appear on the active staff list?  Yes, he spends the first part of my predicate (contract_end is null), but it does not work (at least by my understanding) past the second part of the predicate which is position_end has the value NULL because there not even a record is entered in the comics!  Why would he appear?  Is it because of the LEFT JOIN or a NULL rule type, I'm not aware of?  ...

    It's the outer join.

    When you say

    Employees are

    LEFT JOIN emp_positions ON ep.emp_id = es.emp_id ep

    then, at the time when the WHERE clause is evaluated, the result set contains at least 1 row for each line of employees.  If there is no line in emp_postitions that meet the join condition, then all the columns that should be provided by the emp_positions table will be NULL. This is precisely what concerns the outer join.

    Think about it for a minute.  NULL means the absence of any value.  Is there is no corresponding row in the emp_positions table, then there is no value for emp_position.position_end.  If so doesn't; "have a value, then, by definition, it is NULL.

    It if were not NULL, then this would mean that it had a value.  Would what value?  Why the request would give him one value rather than another?

    Thanks for the display of the data of the sample; It's always useful!

  • Left join between two tables using two different conditions

    I have following three tables with their data, as shown below.

    CREATE TABLE TIREMASTERPROCESS_TEMP
    (
    PRODUCTIONCODE TANK (12 BYTES),
    FIELDNAME CHAR (12 BYTES),
    DATACHR VARCHAR2 (60 BYTE),
    REVISIONNO TANK (3 BYTES),
    DATANUM NUMBER (9.4)
    )
    Whether the table c. and its sample data are like

    FIELDNAME DATACHR REVISIONNO DATANUM PRODUCTIONCODE
    AB No. Nch 1 100 0
    AB No. Nch 1 108 0
    AB No.-of-Nch 1 1 0
    Ass42 teased dishes 1 0
    Ass42 BTDrumNo1 BTD-051 1 0
    AB53 BTDrumNo1 BTD-051 104 0


    CREATE TABLE materialcode
    (
    UPPERMATERIALCODE CHAR (20),
    PROCESSNO TANK (3),
    PROCESSADOPTDATE TANK (9)

    )
    Whether the table b. and its sample data are like

    UPPERMATERIALCODE PROCESSNO PROCESSADOPTDATE
    Ass42 1 20120717
    AB53 108 20121121
    111 20111104 AS05
    104 20120928 AS30


    CREATE TABLE BUILDINGSCHEDULEMASTER
    (
    BUILDINGSIZE TANK (5 BYTES),
    GTCODE FLOAT (4 BYTES),
    TIREPERCART NUMBER (3.0).
    BUILDINGLOT NUMBER (3.0)
    )
    Whether table and its sample data are like

    BUILDINGSIZE GTCODE TIREPERCART BUILDINGLOT
    AB42A 4 12 ass42
    AB53A 4 88 AB53
    AS30A AS30 4 80
    BF03A 1 90 BF03


    Now, I need to get some data in these fields by using the suite of mappings.

    « PR_ » || Trim (a.BUILDINGSIZE) | ' / MPL2' Processid,--PRIMARY KEY
    TO_DATE (substr (NVL(b.PROCESSADOPTDATE,'19800101'), 7, 2) |) » /'|| SUBSTR (NVL(b.PROCESSADOPTDATE,'19800101'), 5, 2) | » /'|| SUBSTR (NVL(b.PROCESSADOPTDATE,'19800101'), 1, 4). (' 01:00:00 ',' dd-mm-yyyy hh24:mi:ss') starteff, to_date (SUBSTR (NVL(b.PROCESSADOPTDATE,'19800101'), 7, 2) |) » /'|| SUBSTR (NVL(b.PROCESSADOPTDATE,'19800101'), 5, 2) | » /'|| SUBSTR (NVL(b.PROCESSADOPTDATE,'19800101'), 1, 4). (' 01:00:00 ',' dd-mm-yyyy hh24:mi:ss') startDate.
    b.PROCESSNO revisioncodeid,
    a.BUILDINGLOT tirepercart ,
    CASE WHEN c.FIELDNAME = 'BTDrumNo1' then c.DATACHR end drumtype1.
    BOX WHEN (trim (C.DATACHR) = '1' and trim (C.FIELDNAME) = "No. Nch") and THEN click 'YES '.
    ANOTHER 'NO '.
    END may-BUG,
    case
    When c.FIELDNAME = 'Wavy'
    AND c.DATACHR = 'Use' THEN on 'YES '.
    When c.FIELDNAME = 'Wavy'
    AND c.DATACHR <>'Use' THEN 'NO '.
    fine wavy


    Now for the tables A and B I have the simple join as condition

    a.GTCODE = b.UPPERMATERIALCODE

    But I have to use two different left join conditions to join the table B and C to calculate the RESP fields according to the condition.
    Now, I have to use

    (trim (b.UPPERMATERIALCODE)). » -'|| Trim (b.PROCESSNO) = Trim (c.PRODUCTIONCODE) | » -'|| Trim (c.REVISIONNO)

    condition to get the data for the WAVY and DRUMTYPE1 fields.

    But at the same time, I have to use

    substr (Trim (b.UPPERMATERIALCODE), 1, 2). » -'|| Trim (b.PROCESSNO) = Trim (c.PRODUCTIONCODE) | » -'|| Trim (c.REVISIONNO)

    conition to derive the CHAFER field.

    And for this reason I am come so many duplicates and do not correct results for JUNEBUG, WAVY, DRUMTYPE1, and STARTDATE field.

    I need some advice as how can I do so that I get the correct results without duplicates for the PRIMARY KEY.

    Thank you

    Mahesh

    It would have been easier to answer if you gave us your example query that gives incorrect results - which both show us what you are doing and give us a starting point.
    Insert instructions for data, rather than only the data would have helped too, making it more quick to test this point.
    You do not show what you have done with your two outer join criteria, but I think you need to list TIREMASTERPROCESS_TEMP in your query twice, with alias names. Here's what I did:

    select a.BUILDINGSIZE, a.GTCODE, b.PROCESSNO ,  c1.FIELDNAME, c1.DATACHR, C2.FIELDNAME, C2.DATACHR
    , CASE WHEN c1.FIELDNAME='BTDrumNo1' then c1.DATACHR end drumtype1
    , CASE WHEN (trim(c2.DATACHR) = '1' and trim(c2.FIELDNAME) = 'No-of-Nch') THEN 'YES' ELSE 'NO' END CHAFER
    , case when c1.FIELDNAME='Wavy' AND c1.DATACHR='Use' THEN 'YES'
           when c1.FIELDNAME='Wavy' then 'NO' else null end wavy
    from BUILDINGSCHEDULEMASTER        A
    join materialcode b on a.GTCODE=b.UPPERMATERIALCODE
    left outer join TIREMASTERPROCESS_TEMP c1
       ON trim(b.UPPERMATERIALCODE)||'-'||trim(b.PROCESSNO) = trim(c1.PRODUCTIONCODE)||'-'||trim(c1.REVISIONNO)
    left outer join TIREMASTERPROCESS_TEMP c2
       ON substr(trim(b.UPPERMATERIALCODE),1,2)||'-'||trim(b.PROCESSNO) = trim(c2.PRODUCTIONCODE)||'-'||trim(c2.REVISIONNO)
    

    C1 is an alias for the TIREMASTERPROCESS_TEMP line which is necessary for drumtype1 and wavy, c2 is an alias for the TIREMASTERPROCESS_TEMP line required for JuneBug. There was some minor errors in your calculations of field I tried to correct.

    The results are:

    BUILD GTCO PRO FIELDNAME    DATACHR    FIELDNAME    DATACHR    DRUMTYPE1  CHA WAV
    ----- ---- --- ------------ ---------- ------------ ---------- ---------- --- ---
    AB53A AB53 108                         No-of-Nch    1                     YES
    AB42A AB42 1   BTDrumNo1    BTD-051    No-of-Nch    1          BTD-051    YES
    AB42A AB42 1   Wavy         NotUse     No-of-Nch    1                     YES NO
    AS30A AS30 104                                                            NO
    

    Hope this helps,
    David

  • strange result of Left Join 11 GR 2.

    It is a strange result of Left Join
    Why the result is 0 record?
    select * from v$version;
    
    BANNER
    -------------------------------------------------------
    Oracle Database 11g Release 11.2.0.1.0 - Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE    11.2.0.1.0      Production
    TNS for 32-bit Windows: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production
    Select * From
    (Select 1 aaa From DUAL) A
    LEFT JOIN
    (Select 2 bbb From DUAL Where '1' IN ('2','3')) B
    ON A.aaa = B.bbb;
    
    no rows selected
    Old Left Join syntax does not work, too :-(
    Select * From
    (Select 1 aaa From DUAL) A,
    (Select 2 bbb From DUAL Where '1' IN ('2','3')) B
    where A.aaa = B.bbb(+);
    
    no rows selected

    Aketi Jyuuzou wrote:
    It is a strange result of Left Join
    Why the result is 0 record?

    I guess that the rewrite of the query with the optimizer is the origin of the problem.
    Say the 10053 trace? I don't have access to the database 11 GR 2 now to test.
    You can see if the advice of line NO_REWRITE or NO_QUERY_TRANSFORMATION gives the desired result.

  • LEFT JOIN question

    Hello

    Here's 2 queries. First one help for the joints and the second query uses a join ancient. The first works very well and I tried to write the 2nd one to work exactly like the first. I don't know where to put the sub condition sysdate in 2nd query such that there operator.

      AND trunc(SYSDATE) BETWEEN hapf.effective_start_date(+) AND
           hapf.effective_end_date(+)
    

    1.

    SELECT papf.full_name,
           hapf.name position_name
      FROM per_people_x       papf,
           per_assignments_x  pax,
           hr_all_positions_f hapf
     WHERE papf.person_id = pax.person_id
           AND pax.position_id = hapf.position_id(+)
           AND trunc(SYSDATE) BETWEEN hapf.effective_start_date(+) AND
           hapf.effective_end_date(+)
    

    2.

    SELECT papf.full_name,
           hapf.name position_name
      FROM per_people_x      papf,
           per_assignments_x pax
      LEFT JOIN hr_all_positions_f hapf
        ON (pax.position_id = hapf.position_id)
     WHERE papf.person_id = pax.person_id
    

    Any suggestion is appreciated.

    Thank you

    KK

    SELECT papf.full_name,

    hapf. Name position_name

    THE women's wear per_people_x

    JOIN THE

    Pax per_assignments_x

    ON)

    PAPF.person_id = pax.person_id

    )

    LEFT JOIN

    hr_all_positions_f hapf

    ON)

    Pax.POSITION_ID = hapf.position_id

    AND

    trunc (sysdate) BETWEEN hapf.effective_start_date AND hapf.effective_end_date

    )

    /

    SY.

  • LEFT JOIN and performance

    Hi guys,.

    I inherited a previous devloper the query below. T_MAXVALUES has 100,000 rows and T_STA_ERG about 1 m.

    The performance is so bad, it works for 5 hours now and I have nothing so I can´t say much about the data of test or how it should look.

    It works on Oracle 11 g and I can´t get my head around all JOIN clauses and the ultimate goal but sense that there could be a better way

    to achieve what is tried below. All of you guru´s able to immediately spot the big failures?

    SELECT DISTINCT T1. PARAMETER, T1. ZERL_MATRIX, T1. MONTHS, T1. ADDITIONAL_CRI,

    DECODE (H2. MRL, NULL, (DECODE (H1. MRL, NULL, (DECODE (H3. MRL, NULL, (DECODE (H4. MRL, NULL, NULL, 'R')), 'R')), M1. MRL)), H2. MRL)

    OF T_STA_ERG T1

    LEFT JOIN (SELECT PARAMETER, ZERL_MATRIX_2, MRL

    OF T_MAXVALUES, WHERE ZERL_MATRIX_1 IS NULL) H1

    ON T1. PARAMETER = H1. PARAMETER

    AND substr (T1. ZERL_MATRIX, 4, 3) = H1. ZERL_MATRIX_2

    LEFT JOIN (SELECT PARAMETER, ZERL_MATRIX_1, ZERL_MATRIX_2, MRL

    OF T_MAXVALUES

    WHERE ZERL_MATRIX_1 IS NOT NULL) H2

    ON T1. PARAMETER = H2. PARAMETER

    AND substr (T1. ZERL_MATRIX, 1, 3) = H2. ZERL_MATRIX_1

    AND substr (T1. ZERL_MATRIX, 4, 3) = H2. ZERL_MATRIX_2

    LEFT JOIN (SELECT PARAMETER, ZERL_MATRIX_2, MRL

    OF T_MAXVALUES

    WHERE ZERL_MATRIX_1 IS NULL) H3

    ON T1. PARAMETER = H3. PARAMETER

    LEFT JOIN T_MAXVALUES H4

    ON substr (T1. ZERL_MATRIX, 1, 3) = H4. ZERL_MATRIX_1

    The idea is to get maxvalues lines that at least match the lines of t. The game minimum is the game of columns of the parameter (type 3), or matches the matrix 1 (type 4).

    If you get all possible matches, and you will then take the MRLS of the best match: better if the parameter, matrix1 and matrix2 all game, then if parameter and matrix2 match, etc.

    What I have not included here are a test for null matrix1. If a match where parameter and matrix2 match, but there's a matrix1 value that does not match the value in T matrix1, will have to be thrown out, then just add this additional condition in the CASE statement.

    Untested of course:

    Select T1. PARAMETER, T1. ZERL_MATRIX, T1. MONTHS, T1. ADDITIONAL_CRI, Max (MRL) keep dense_rank of first order by type)

    Of

    (SELECT T1. PARAMETER, T1. ZERL_MATRIX, T1. MONTHS, T1. ADDITIONAL_CRI,

    -case when T1. PARAMETER = H.PARAMETER and substr (T1. ZERL_MATRIX, 1, 3) = H2. ZERL_MATRIX_1 AND substr (T1. ZERL_MATRIX, 4, 3) = H2. ZERL_MATRIX_2 then 1

    When T1. PARAMETER = H.PARAMETER and substr (T1. ZERL_MATRIX, 4, 3) = H1. ZERL_MATRIX_2 then 2

    When T1. PARAMETER = H.PARAMETER then 3

    When substr (T1. ZERL_MATRIX, 1, 3) = H.ZERL_MATRIX_1 then 4

    end match_type, h.mrl

    OF T_STA_ERG T1

    LEFT JOIN T_MAXVALUES h on (T1. PARAMETER = H.PARAMETER or substr (T1. (ZERL_MATRIX, 1, 3) = H.ZERL_MATRIX_1)

    )

    Group T1. PARAMETER, T1. ZERL_MATRIX, T1. MONTHS, T1. ADDITIONAL_CRI;

  • LEFT JOIN increases the number of lines

    Hi guys,.

    I had a problem, my left join retrieves multiple values. I know he has only 252 in there that correspond to the place where

    condition. If I use the table in a left join with the same condition where my row count increases.

    -1176 lines

    Select count (erg_ID) of

    MySchema. T_STA_ERG sta_erg

    INNER JOIN T_MEN hoechst

    ON sta_erg. PARAMETER = hoechst. PARAMETER

    AND sta_erg. JAHR = 2014

    where sta_erg. MESSERG_KNG = 'A' AND sta_erg. MESSERG_ALPHA IN ('03 ") and sta_erg. NORM_MESS is null

    -252 lines

    Select distinct erg_ID myschema. T_STA_ERG sta_erg where sta_erg. MESSERG_KNG = 'A' AND sta_erg. MESSERG_ALPHA IN ('03 ") and sta_erg. NORM_MESS is null

    any clue´s how I can build in conditions in my join which would not increase the results of the line?

    Why not just an inner join then?

  • Double left join creates a unwanted loop...

    I have therefore two paintings, I need to extract the counts of "tickets".

    I want to have the date given match then I use a 'connect by level' so that the same dates without data will have records in the result set.

    There are two tables I want to join on this "timeline" when I join each of them that individually, it works but when I join together that there is an order of operations issue I'm not sure how to move.

    ORIGINAL DATA:

    TABLE SMINCREQ:

    OPEN_DATE NUMBER
    JANUARY 12, 2015IM392039
    JANUARY 12, 2015IM399495
    JANUARY 12, 2015RM394950
    JANUARY 13, 2015IM394958
    JANUARY 13, 2015
    RM394958

    TABLE SMINTERACTIONS:

    OPEN_DATE INCIDENT_ID
    JANUARY 12, 2015SD394858
    JANUARY 12, 2015SD399495
    JANUARY 12, 2015SD394950
    JANUARY 13, 2015SD394958
    JANUARY 13, 2015
    SD394958

    THE QUERY:

    SELECT to_char(DAYS_,'DD-MON-YYYY'),
          
          sum(decode(INSTR(SMINCREQ."NUMBER",'IM'),'1','1',0)) "INCIDENT",
          sum(decode(INSTR(SMINCREQ."NUMBER",'RM'),'1','1',0)) "REQUEST"
         --sum(decode(INSTR(SMINTERACTIONS.INCIDENT_ID,'SD'),'1','1',0)) "INTERACTION"  
          FROM
      ( SELECT (TRUNC(to_date(SYSDATE-ROWNUM),'DD')) DAYS_ FROM DUAL
    CONNECT BY LEVEL <= (SELECT 14 FROM DUAL)
      ) THE_TIMELINE
        LEFT OUTER JOIN SMINCREQ ON  (to_char(DAYS_,'DD-MON-YYYY')=to_char(SMINCREQ.OPEN_TIME,'DD-MON-YYYY')  and (OPEN_GROUP like '%HELP%'))
        --LEFT OUTER JOIN SMINTERACTIONS on (to_char(DAYS_,'DD-MON-YYYY')=to_char(SMINTERACTIONS.OPEN_TIME,'DD-MON-YYYY')  and PRIMARY_ASSIGNMENT_GROUP like '%HELP%')
        GROUP BY to_char(DAYS_,'DD-MON-YYYY') ORDER BY to_char(DAYS_,'DD-MON-YYYY')
      ;
    
    

    When I run the present and just get the number of SMINCREQ is

    DATEINCIDENTSREQUEST
    JANUARY 12, 20151034
    JANUARY 13, 20155910

    When I run the query for SMINTERACTIONS I get

    DATEINTERACTION
    JANUARY 12, 201555
    JANUARY 13, 201550

    When I try to run the two left joins them together I get:

    DATEINCIDENTSAPPLICATIONSINTERACTIONS
    JANUARY 12, 201556652205885
    JANUARY 13, 201529505003450

    I know that what is happening is a loop where the date is is developed in a relationship 1 to many through the joints and then the GROUP is not the case until the end.

    What I want to achieve is:

    DATEINCIDENTSREQIESTINTERACTION
    JANUARY 12, 2015103455
    JANUARY 13, 2015591050

    Thanks for the tips

    I decided to go this route that will just join the new data (INTERACTIONS) of INCIDENTS already implemented and APPLICATIONS:

    SELECT NULL LINK,DAYS,INCIDENT,"REQUEST",sum(decode(INSTR(SMINTERACTIONS.INCIDENT_ID,'SD'),'1','1',0)) "INTERACTION" from(
    
    SELECT to_char(DAYS_,'DD-MON-YYYY') DAYS,sum(decode(INSTR(SMINCREQ."NUMBER",'IM'),'1','1',0)) "INCIDENT",
          sum(decode(INSTR(SMINCREQ."NUMBER",'RM'),'1','1',0)) "REQUEST"
          FROM
      ( SELECT (TRUNC(to_date(SYSDATE-ROWNUM),'DD')) DAYS_ FROM DUAL
     CONNECT BY LEVEL <= (SELECT 14 FROM DUAL)
      ) THE_TIMELINE
        LEFT OUTER JOIN SMINCREQ ON  (to_char(DAYS_,'DD-MON-YYYY')=to_char(SMINCREQ.OPEN_TIME,'DD-MON-YYYY')  and (OPEN_GROUP like '%HELP CENTER%')
    )
    
        GROUP BY to_char(DAYS_,'DD-MON-YYYY') ORDER BY to_char(DAYS_,'DD-MON-YYYY')
    ) LEFT JOIN SMINTERACTIONS on (DAYS=to_char(OPEN_TIME,'DD-MON-YYYY') and (PRIMARY_ASSIGNMENT_GROUP like '%HELP CENTER%'))
    GROUP BY DAYS,INCIDENT,"REQUEST" order by DAYS ASC;
    

    Thanks for all the entries...

  • Left join

    Hello world

    Im trying to create the query that displays the values that are not available in the other table.

    Scenario:

    I have two tables, the material and materialfolder. I want to display documents that are not available in materialfolder.

    Here's my query

    SELECT m.material_id
        ,  m.MATERIAL_TYPE_ID
        ,  m.name
        ,  m.created
            FROM material m
            LEFT  JOIN materialfolder mf ON m.material_id = mf.material_id
            where to_char(m.CREATED, 'yyyy') >= ('2011')
            and to_char(m.CREATED, 'yyyy') <= ('2013');
    
    

    The result does not show the correct values. Don't know what my error here...

    Hoping that someone could help me.

    Thank you.

    Kind regards

    Ed

    Hello

    If you just want to know the values that are not available in materialfolder, use a NOT EXISTS condition:

    SELECT m.material_id

    m.MATERIAL_TYPE_ID

    $m.name

    m.created

    MATERIAL m

    If NOT EXISTS (select null from materialfolder mf

    where m.material_id = mf.material_id

    )

    AND m.CREATED > = TO_DATE('01/01/2011', 'dd/mm/yyyy') AND m.CREATED< to_date('01/01/2014',="">

  • LEFT JOIN DUPLICATION PROBLEM

    Hello

    I'm having a problem with the left join query, when I join table a two table based on column task1 I get duplicate in table1.task1, table1.price.

    Table1. Task1Table1. Pricetable2. Task1table2. Resourcetable2. Price
    001100001A50
    001100001B250

    How can I make a request to get a result as below.

    Table1. Task1Table1. Pricetable2.Task2table2. Resourcetable2. Price
    001100001A50
    001B250

    Thank you.

    Note that your query uses an inner join. Your original question mentioned a join left, generally interpreted as meaning a left OUTER join.

    Anyway, according to Frank, you can use the BREAK command in SQL * Plus for the goal sought through formatting. You can also use an analytical function as Roger suggests. I think ROW_NUMBER() might do the trick, but we must be clear about the criteria for partitioning and ordering the results, for example

    WITH table1 AS (
      SELECT '001' AS task1
           , 100 AS price
      FROM   dual
    ), table2 AS (
      SELECT '001' AS task1
           , 'A' AS resources
           , 50 AS price
      FROM   dual
      UNION ALL
      SELECT '001' AS task1
           , 'B' AS resources
           , 250 AS price
      FROM   dual
    )
    SELECT DECODE(ROW_NUMBER() OVER (PARTITION BY t1.task1, t1.price ORDER BY t2.resources, t2.price),1,t1.task1) AS task1_alt
         , DECODE(ROW_NUMBER() OVER (PARTITION BY t1.task1, t1.price ORDER BY t2.resources, t2.price),1,t1.price) AS price_alt
         , t2.task1 AS task_with_resource
         , t2.resources
         , t2.price
    FROM   table1 t1
    INNER JOIN table2 t2
    ON     t1.task1 = t2.task1
    ORDER BY t1.task1, t1.price, t2.resources, t2.price;
    
  • How to avoid the union and use a left join

    Hello

    I have the following tables

    {code}

    create the table mainTable

    (col1 varchar2 (2) varchar2 (2) col2, col3 varchar2 (2), col4 varchar2 (2));

    create table secTable

    (col1 varchar2 (2));

    create the table secTable1

    (col2 varchar2 (2));

    create the table secTable2

    (col3 varchar2 (2));

    Insert in maintable

    values ('a', 'b', 'this,' would be ');

    Insert in maintable

    values (', 'o', 'n', 'p');

    insert into secTable

    values ('a');

    insert into secTable1

    values ('b');

    insert into secTable2

    values ('c');

    commit;

    {code}

    I made a request, drank, I would use join without clause union how can I change to receive the same result as the following query?

    {code}

    Select t1.*, 'bad value' | T1.Col1
    from maintable t1
    T1.Col1 left join t2 = t2.col1 sectable
    where t2.col1 is null
    Union of all the
    Select t1.*, 'bad value' | T1.col2
    from maintable t1
    Join t2 left on t1.col1 = t2.col2 sectable1
    where t2.col2 is null
    Union of all the
    Select t1.*, 'bad value' | T1. COL3
    from maintable t1
    Join t2 left on t1.col1 = t2.col3 sectable2
    where t2.col3 is null

    {code}

    Thank you

    Coco

    Like this?:

    SQL > SELECT col1, col2, col3, col4, xvalue

    2 from (SELECT m0.*

    3, NVL (t0.col1, 'bad value t0' | m0.col1) t0_col1

    4, NVL (t1.col2, 'bad value t1' | m0.col2) t0_col2

    5, NVL (t2.col3, 'bad value t2' | m0.col3) t0_col3

    Maintable m0 6

    LEFT OUTER JOIN sectable t0 7

    8. WE (m0.col1 = t0.col1

    9 AND t0.col1 IS NULL)

    10 LEFT OUTER JOIN sectable1 t1

    11. WE (m0.col1 t1.col2 =

    12 AND t1.col2 IS NULL)

    13 LEFT OUTER JOIN t2 sectable2

    14. WE (m0.col1 = t2.col3

    15 t2.col3 AND IS NULL))

    16 UNPIVOT INCLUDES NULL values (xvalue wrongly IN (t0_col1, t0_col2, t0_col3))

    17 ORDER BY xvalue

    18.

    COL1 COL2 COL3 COL4 XVALUE

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

    a b c d bad value t0 a

    m o n p bad value m t0

    a b c d bad value t1 b

    m o n p o t1 value of evil

    a b c d bad value t2 c

    m o n p value t2 n bad

    6 selected lines.

  • Interesting behavior of left join

    We will create 3 tables as follows:


    CREATE TABLE "A1" ()"A1_ID" NUMBER ENABLE NON NULL,CONSTRAINT "A1_PK" SELECT the PRIMARY KEY ('A1_ID') );

    CREATE TABLE "A2" ()"A2_ID" NUMBER ENABLE NON NULL,CONSTRAINT "A2_PK" SELECT the PRIMARY KEY ('A2_ID'));

    CREATE TABLE "A12" ()'A12_ID' ENABLE NUMBER NOT NULL,'A1_ID' ENABLE NUMBER NOT NULL,'A2_ID' ENABLE NUMBER NOT NULL,"A12_PK" PRIMARY KEY ('A12_ID'), CONSTRAINTREFERENCES of FOREIGN ("A1_ID") of CONSTRAINT "A12_A1_FK1" "BUTUNLESIK" KEY "" A1 "("A1_ID") ENABLE,KEY REFERENCES FOREIGN ("A2_ID") of CONSTRAINT 'A12_A2_FK1' 'BUTUNLESIK '. ("" A2 "("A2_ID") ALLOW);

    We insert the values as follows:

    Insert into A1 values (1);

    Insert into A1 values (2);

    Insert into A1 values (3);

    Insert 4 A1;

    Insert into A1 values (5);

    Insert into A1 values (6);

    Insert into A2 values (1);

    insert into values A12 (1,1,1);

    Tables a1 and A2 are just simple tables with primary keys and A12 table contains many-to-many relationship between them.

    When I run the query below,

    SELECT * A1 A1 A12 A12 LEFT JOIN ON a1.a1_id = a12.a1_id A2 LEFT JOIN A2 ON a2.a2_id = a12.a2_id WHERE a2.a2_id IS NULL;

    I get the following results, as I predicted:

    A1_ID A12_ID A1_ID A2_ID A2_ID

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

    6

    5

    4

    3

    2

    However when I run the second query below (where I select only the a1 id column instead of "*")

    SELECT a1.a1_id A1 A1 A12 A12 LEFT JOIN ON a1.a1_id = a12.a1_id A2 LEFT JOIN A2 ON a2.a2_id = a12.a2_id WHERE a2.a2_id IS NULL;


    I get nothing, no lines have been selected. When I look at the plan of the second query I see a predicate to filter such as "'NULL IS NOT NULL". " I guess that this does not return results. Is this a bug, or y at - it a satisfactory explanation for this behavior?

    Step 1 - check the execution plans.

    At first glance, this looks like a variant of https://forums.oracle.com/thread/2594321

    Concerning

    Jonathan Lewis

  • Left join of the two tables and multiple values into a single value separated by commas

    Hello

    I have following tables with their structures and their data as below.

    CREATE TABLE 'BETODI '. "" BETINFO ".

    (

    VARCHAR2 (8 BYTE) "CURRENTPRESS."

    ENABLE 'TYPEIDCONTAINER' VARCHAR2 (30 BYTE) NOT NULL

    )

    INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ('A24G', 'PMC');

    INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ('A24D', 'Pensky-MARTENS');

    INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ("A25D", "CMP");

    INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ('A25G', 'PMC');

    INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ('A26D', 'PMC');

    INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ('A26G', 'PMC');

    INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ("A32G", "V-BFC3");

    INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ('A32D', "V-BFC2");

    CREATE TABLE 'BETODI '. "" BETMASTER ".

    (

    ACTIVATE THE "CUREPRESS" TANK (5 BYTES) NOT NULL,

    ACTIVATE THE "TYPE" VARCHAR2 (5 BYTE) NOT NULL,

    NUMBER (5.0) "LASTPCIRIM".

    )

    INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A24', '45 M 8', 15);

    INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A25', 42 16', 15);

    INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ("A26", 16' 45, 15);

    INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ("A27", '45 M 34', 16);

    INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A28', '45 M 34', 16);

    INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A29', '45 M 34', 16);

    INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A30', '45MCH', 15);

    INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ("A31", "45MCH", 16);

    INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A32', '45MCH', 16);

    INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A33', '45MCH', 16);

    INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ("A34", "45MCH", 16);

    These two tables have left join as

    BETMASTER. CUREPRESS = substr (BETINFO. CURRENTPRESS, 1, 3)

    now I want to have the data in the two tables with fields Curepress, Lastpcirim, typeidcontainer.

    Also something like

    Make a group of typeidcontainer if this value is greater than 1 by press separated the values of semicolon (;)

    So, for example above, we should be given as

    A24 PMC 15; PENSKY-MARTENS

    A25 15 PMC

    A26 15 PMC

    A27 16 (NULL)

    A28 16 (NULL)

    A30 15 (NULL)

    A31 16 (NULL)

    A32 16 BFC2-V; V BFC3

    A33 16 (NULL)

    A34 16 (NULL)

    How could do?

    My current request is as

    Select distinct Curepress, lastpcirim, typeidcontainer

    BETMASTER STD left join INF BETINFO

    on the trim (STD. CUREPRESS) = substr (trim (INF. CURRENTPRESS), 1, 3)

    but I am unable to get the values separated by commas.

    Any help would be appreciated.

    Thank you

    Mahesh.

    Hi, Mahesh,

    If you want to only 1 row of output for each distinct combination of currentpress and lastpcirim?  This sounds like a job for GROUP BY.

    And you want the row to contain a list of all different typidcontainers-delimited?  This sounds like a job for the aggregate LISTAGG function.

    WITH joined_data AS

    (

    SELECT DISTINCT

    MST.curepress, mst.lastpcirim, inf.typeidcontainer

    OF betmaster STD

    LEFT JOIN betinfo ON TRIM (mst.curepress) inf = SUBSTR (TRIM (inf.currentpress)

    1

    3

    )

    )

    SELECT curepress, lastpcirim

    LISTAGG (typeidcontainer, ',')

    THE Group (ORDER BY typeidcontainer) AS container_list

    OF joined_data

    Curepress GROUP, lastpcirim

    ;

    Unfortunately, you can't say LISTAGG (DISTINCT ...), so you should always get the separate containers how you already are.  (Note that the subquery is just what you posted).

    Thanks for posting the CREATE TABLE and INSERT statements; It is very useful.  Don't forget to tell what version of Oracle you are using.  LISTAGG was new in Oracle 11.2.

    Why not add CHECK constraints (and perhaps triggers) to your tables, so that curepress and currentpress are not stored with the head or trailing spaces?  Then you wouldn't need to use the PAD in queries like this, and your code would be simpler and more effective.

  • ORA-01417: a table can be external joined as another table

    Hi, I use Oracle 8i and could not use LEFT JOIN. So I need to use (+) instead.
    But I encounter ORA-01417 for = G.COL5 of I.COL3 (+)

    Complete the order as follows:
    SELECT *.
    B, A, C, D, J, K, L, E, F, G, H, I
    WHERE B.COL1 = 'ABC'
    AND B.COL1 = A.COL1 AND B.COL2 = A.COL2 AND B.COL3 = A.COL3
    AND C.COL1 = B.COL1 AND C.COL2 = B.COL6 AND C.COL3 = B.COL7
    AND B.COL1 = D.COL1 (+) AND D.COL2 (+) = B.COL6
    AND A.COL1 = J.COL1 (+) AND A.COL2 = J.COL2 (+)
    AND B.COL1 = K.COL1 (+) AND (+)-K.COL2 AND B.COL11 = B.COL6 = K.COL3 (+) AND B.COL12 = K.COL4 (+)
    AND A.COL1 = L.COL1 (+) AND L.COL2 (+) = A.COL2 AND A.COL3 = L.COL3 (+)
    AND E.COL1 = 'ABC' AND E.COL2 (+) (+) = C.COL20 AND E.COL3 (+) = C.COL21
    AND F.COL1 (+) = 'ABC' AND F.COL2 (+) = C.COL20
    AND G.COL1 = 'ABC' AND G.COL2 (+) (+) = B.COL11 AND G.COL3 (+) = B.COL12
    AND H.COL1 (+) = 'ABC' AND H.COL2 (+) = "PINCH" AND H.COL3 (+) = G.COL5
    AND I.COL1 (+) = 'ABC' AND I.COL2 (+) = "PINCH" AND I.COL3 (+) = G.COL5* AND = A.COL5 I.COL4 (+) AND I.COL5 (+) = "0001"

    Please notify.
    Thanks in advance.

    Hello

    981637 wrote:
    ... How to re-write the script according to your suggestion?

    Maybe something like:

    SELECT  *
    FROM      (     -- Begin in-line view abc
              SELECT     b.col4      AS b_col4
              ,     c.col4      AS c_col4
         --     ,     ...      -- Whatever columns you want to display in the main query
              FROM     a
              ,      b
              ,      c
              WHERE      b.col1          = a.col1
              AND     b.col2          = a.col2
              AND     b.col3          = a.col3
              AND     c.col1 (+)      = 'ABC'
              AND     c.col2 (+)      = a.col4
              AND     c.col3 (+)      = a.col5
         ) abc     -- End in-line view
    ,     d
    WHERE     d.col1 (+)     = 'ABC'
    AND     d.col2 (+)      = 'LOC'
    AND     d.col3 (+)      = abc.c_col4
    AND     d.col4 (+)      = abc.b_col4
    ;
    

    I can't say with certainty without examples of data (CREATE TABLE and INSERT statements) and the results desired from these data.

    In your real problem, the other tables can be joined to the a, b and c of the subquery (I assume it will be the most convenient way to do so), or they can be reached at abc in the main query.

Maybe you are looking for