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;

Tags: Database

Similar Questions

  • left join problem?

    I want left join two tables (a, b) where a.account = b.accountNumber number and this join must occur only for the specified account numbers. For this, my request is as follows.

    Select a.PRIMARY_FIRST_NAME, a.PRIMARY_LAST_NAME, a.ACCOUNT_NUMBER, a.PRIMARY_SSN, a.ADDRESS_1, a.ADDRESS_2,
    a.CITY, a.STATE, a.ZIP, b.phone_number, cust_account_details a b.status
    Join phone_data b left
    on
    a.Account_Number = b.account_number
    and
    a.Account_Number in
    ('11 ', ' 22')


    The above does not work correctly. the join occurs not only for the numbers in the range. What could be the problem?

    Try this: -.

    select a.PRIMARY_FIRST_NAME,a.PRIMARY_LAST_NAME,a.ACCOUNT_NUMBER,a.PRIMARY_SSN,a.ADDRESS_1,a.ADDRESS_2,
    a.CITY,a.STATE,a.ZIP,b.phone_number,b.status from cust_account_details a
    left join phone_data b
    on
    a.account_number=b.account_number
    *where*
    a.account_number in
    ('11','22')
    

    Thank you.

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

  • 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 with three-table join query

    I am trying to create a query that left me speechless. Most of the query is simple enough, but I have a problem I do not know how to solve.

    Background:
    We have stock stored in i_action.

    We have the attributes available for each type of action. The attributes available for each action are described in shared_action_attribute. Each type of action can have three attributes or none at all.

    We have the values stored for the attributes in i_attribute_value.

    An example says:
    We have a transfer action (action_code B4). The action of B4 entry into i_action records the fact that the transfer took place and the date at which he spoke. The attributes available for a transfer action are the function code receiver, the receiving unit number and the reason of transfer code. These types of attributes available and their order are stored in shared_action_attribute. The actual values of the attributes for a specific action of transfer are stored in i_attribute_value.

    Now i_action and i_attribute_value can be connected directly in action_seq in i_action and ia_action_seq in i_attribute_value. A left join on these two tables provides results for all actions (including actions that have no attributes) and assign values (see Query 1 below).

    There are two questions. First of all, I want only the first two attributes. To specify the attributes of the first two, I also i_attribute_value a link to shared_action_attribute (which is where the order is stored). I can build a simple query (without the left join) which connects the three tables, but then shares without attributes would be excluded from my result (see Query 2 below).

    The second problem is that I'd actually a row returned for each action with first_attribute and second_attribute in the form of columns instead of two lines.

    The final query will be used to create a materialized view.

    Here are the tables and examples of what is stored in the:

    TABLE i_action
    Name Type
    ----
    ACTION_SEQ NUMBER (10)
    DATE OF ACTION_DATE
    ACTION_CODE VARCHAR2 (3)
    VARCHAR2 (1) DELETED

    EXAMPLE OF LINES
    ACTION_SEQ ACTION_DATE DELETED ACTION_CODE
    ----
    45765668 9 OCTOBER 09 B2 HAS
    45765670 9 OCTOBER 09 BA HAS
    45765672 B6 9 OCTOBER 09A
    45765673 9 OCTOBER 09 B4 HAS
    45765674 9 OCTOBER 09 G1 HAS
    45765675 9 OCTOBER 09 M3 HAS

    TABLE i_attribute_value
    Name Type
    ---
    IA_ACTION_SEQ NUMBER (10)
    SACTATT_SACT_CODE VARCHAR2 (3)
    SACTATT_SAT_TYPE VARCHAR2 (3)
    VARCHAR2 VALUE (50)

    EXAMPLE OF LINES
    IA_ACTION_SEQ SACTATT_SACT_CODE SACTATT_SAT_TYPE VALUE
    ----
    45765668 B2 COA 37 B
    45765670 BA ROA D
    45765670 BA ROR P
    45765672 B6 CAT C
    B4 45765673 RFC E
    45765673 B4 TRC P
    B4 45765673 RUN 7
    45765674 G1 SS 23567
    G1 45765674 ASG W

    TABLE shared_action_attribute
    Name Type
    ---
    SACT_CODE VARCHAR2 (3)
    SAT_TYPE VARCHAR2 (3)
    ORDER NUMBER (2)
    TITLE VARCHAR2 (60)

    EXAMPLE OF LINES
    SACT_CODE SAT_TYPE UNDER THE ORDER
    ----
    B2 ACO 1 Office code
    BA ROR 1 reason to re-open
    Authority of BA ROA 2 reopen
    B6 CAT 1 category
    B4 RFC 1 reception function code
    B4 RUN 2 receives the unit code
    B4 TRC 3 transfer of reason code
    Sequence of G1 SS 1 personal
    Reason for G1 ASG 2 assignment

    QUERY 1:
    It's my current query as well as its results. Most are select simple but only one column is filled using the function analytic last_value (thank you guys). The last column in the view sub stores the value of the attribute. What I want is to replace this single column with two columns named first_attribute and second_attribute and eliminate all other attributes.
    SELECT ia.action_seq, ia.action_date, ia.action_code cod,
    NVL
    (LAST_VALUE (CASE
    WHEN ia.action_code = "G1".
    AND iav.sactatt_sat_type = 'SS '.
    THEN THE VALUE
    WHEN ia.action_code IN ('A0', 'A1')
    THEN '67089'
    END IGNORE NULLS
    ) OVER (PARTITION BY ia.ici_charge_inquiry_seq ORDER BY ia.action_date,
    IA.serial_number, ia.action_seq),
    '67089'
    ) staff_seq,.
    value
    From i_action LEFT JOIN i_attribute_value iav AI
    ON iav.ia_action_seq = ia.action_seq
    WHERE ia.deleted = 'A ';

    ACTION_SEQ ACTION_DA COD STAFF_SEQ VALUE
    ----
    45765668 9 OCTOBER 09 B2 67089 37 B
    45765670 9 OCTOBER 09 BA D 67089
    45765670 9 OCTOBER 09 BA 67089 P
    45765672 9 OCTOBER 09 B6 67089 C
    45765673 9 OCTOBER 09 B4 67089 E
    45765673 9 OCTOBER 09 B4 67089 P
    45765673 9 OCTOBER 09 67089 7 B4
    45765674 9 OCTOBER 09 23567 23567 G1
    45765674 9 OCTOBER 09 G1 23567 W
    45765675 9 OCTOBER 09 M3 23567

    QUERY 2:
    This query is limited to the first two attributes but he also filed actions which have no attributes, and it creates still several lines for each action instead of a single line with two columns for attributes.
    SELECT ia.action_seq, ia.action_date, ia.action_code cod,
    NVL
    (LAST_VALUE (CASE
    WHEN ia.action_code = "G1".
    AND iav.sactatt_sat_type = 'SS '.
    THEN THE VALUE
    WHEN ia.action_code IN ('A0', 'A1')
    THEN '67089'
    END IGNORE NULLS
    ) OVER (PARTITION BY ia.ici_charge_inquiry_seq ORDER BY ia.action_date,
    IA.serial_number, ia.action_seq),
    '67089'
    ) staff_seq,.
    value
    OF shared_action_attribute saa, ims_action AI, ims_attribute_value iav
    WHERE iav.ia_action_seq = ia.action_seq
    AND iav.sactatt_sact_code = saa.sact_code
    AND iav.sactatt_sat_type = saa.sat_type
    AND saa.display_order IN ('1 ', ' 2')
    AND ia.deleted = 'A ';

    ACTION_SEQ ACTION_DA VALUE OF COD
    ----
    45765668 9 OCTOBER 09 B2 67089 37 B
    45765670 9 OCTOBER 09 BA D 67089
    45765670 9 OCTOBER 09 BA 67089 P
    45765672 9 OCTOBER 09 B6 67089 C
    45765673 9 OCTOBER 09 B4 67089 E
    45765673 9 OCTOBER 09 67089 7 B4
    45765674 9 OCTOBER 09 23567 23567 G1
    45765674 9 OCTOBER 09 G1 23567 W

    I found it quite complex to try to write - I hope that I was clear.

    Thank you very much!

    Hello

    You can use an alias for column (such as staff_seq) in the ORDER BY. Unfortunately, it's the only place where you can use it in the same query, where it was defined.
    You can use it anywhere in the super-requetes, however, so you can still work around this problem in assigning the aliases in a subquery and GROUP BY (or other) in a Super query, like this:

    WITH   ungrouped_data      AS
    (
        SELECT ia.action_seq, ia.action_date, ia.action_code,
              NVL
                  (LAST_VALUE (CASE
                                  WHEN ia.action_code = 'G1'
                                   AND sactatt_sat_type = 'SS'
                                     THEN VALUE
                                  WHEN ia.action_code IN ('A0', 'A1')
                                     THEN '67089'
                               END IGNORE NULLS
                              ) OVER (PARTITION BY ia.ici_charge_inquiry_seq ORDER BY ia.action_date, ia.action_seq),
                   '67089'
                  )staff_seq,
               (CASE
                  WHEN display_order = '1'
                  THEN VALUE
               END) first_attribute,
               (CASE
                  WHEN display_order = '2'
                  THEN VALUE
               END) second_attribute
          FROM i_action ia
          LEFT JOIN i_attribute_value iav
               ON iav.ia_action_seq = ia.action_seq
          LEFT JOIN shared_action_attribute
               ON sactatt_sact_code = sact_code
             AND sactatt_sat_type = sat_type
         WHERE ia.deleted = 'A'
    )
    SELECT       action_seq
    ,       action_date
    ,       action_code
    ,       staff_seq
    ,       MIN (first_attribute)          AS first_attribute
    ,       MIN (second_attribute)     AS second_attribute
    FROM       ungrouped_data
    GROUP BY  action_seq
    ,       action_date
    ,       action_code
    ,       staff_seq
    ;
    

    There are other alternatives for special cases, but none of them work in this particular case.

  • Join the problem

    I am currently running Oracle version 11.1.0.7.0. I found a piece of view which I think does not behave as I expect. For me, this looks like a bug in Oracle, but I hope you can show me that this is not a bug and I hurt something else. I was able to reproduce this problem with these table definitions:

    create the table kaw_base
    (base_id number of non-null
    key constraint pk_kaw_base primary.
    subtype_code varchar2 (1)
    );

    create the table kaw_subtype1
    (base_id number of non-null
    key constraint pk_kaw_subtype1 primary.
    Order_Id varchar2 (16).
    constraint fk_subtype1__base
    foreign key (base_id) references kaw_base
    );

    create the table kaw_subtype2
    (base_id number of non-null
    key constraint pk_kaw_subtype2 primary.
    Order_Id varchar2 (16).
    constraint fk_subtype2__base
    foreign key (base_id) references kaw_base
    );

    create the table kaw_ref
    (ref_id number not null
    key constraint pk_kaw_ref primary.
    number of base_id not null
    constraint fk_ref__base
    Reference kaw_base
    );

    create indexes kaw_ref_ndx02
    on kaw_ref (base_id);

    I filled the tables with these data:

    insert into kaw_base
    Select 1, null of union double all the
    Select 2, '1' of any double Union
    Select 3, '1' of any double Union
    Select option 4, '2' from dual;
    Select * from kaw_base;

    insert into kaw_subtype1
    Select 2, '101' of any double union
    Select 3, '102' from dual;
    Select * from kaw_subtype1;

    insert into kaw_subtype2
    Select 4, '103' double;
    Select * from kaw_subtype2;

    insert into kaw_ref
    Select 500 + base_id, kaw_base base_id;
    Select * from kaw_ref;

    I then ran this series of requests to try to give the idea of what I see to this problem:

    -- --------------------------------------------------------
    -This first query shows the ID of lines which
    -must be returned by this query. Get all four rows
    -back and all is good in th world.
    --
    - But just try to add j.order_ID to the results!
    -- --------------------------------------------------------
    Select
    XREF.base_id
    -, j.order_Id
    of kaw_ref xRef
    Join
    -left join
    (select
    a.base_id,
    COALESCE(b.order_Id, c.Order_Id) as Order_Id
    of kaw_base one
    Join kaw_subtype1 b left
    On b.base_id = a.base_id
    c left join kaw_subtype2
    -join kaw_subtype1 c on the left
    On c.base_id = a.base_id
    ) j
    On j.base_id = xref.base_id
    -where j.base_id is not null
    ;

    / * Sample output:
    BASE_ID
    ----------
    1
    2
    3
    4

    4 selected lines.
    */

    -- --------------------------------------------------------
    -What happened? I don't think that adding a column to
    -the selection list should cause the lines to completely
    -disappear.
    --
    -I walk what happens if I change the second LEFT JOIN
    - is the same as the first join?
    -- --------------------------------------------------------
    Select
    XREF.base_id
    j.order_Id
    of kaw_ref xRef
    Join
    -left join
    (select
    a.base_id,
    COALESCE(b.order_Id, c.Order_Id) as Order_Id
    of kaw_base one
    Join kaw_subtype1 b left
    On b.base_id = a.base_id
    c left join kaw_subtype2
    -join kaw_subtype1 c on the left
    On c.base_id = a.base_id
    ) j
    On j.base_id = xref.base_id
    -where j.base_id is not null
    ;

    / * Sample output:

    no selected line.
    */

    -- --------------------------------------------------------
    -Still more curious. It seems to me that this could be
    -treatment he two LEFT joins as INNER joins and only
    -returning data with KAW_BASE and KAW_SUBTYPE1 in
    -common.
    --
    -We will try to change the rear query in a way that both
    -Joined LEFT pointing the two subtype tables and let's
    -also add, in the superfluous, WHERE clause and see what
    -makes for (for us).
    -- --------------------------------------------------------
    Select
    XREF.base_id
    j.order_Id
    of kaw_ref xRef
    Join
    -left join
    (select
    a.base_id,
    COALESCE(b.order_Id, c.Order_Id) as Order_Id
    of kaw_base one
    Join kaw_subtype1 b left
    On b.base_id = a.base_id
    -join kaw_subtype2 c on the left
    c left join kaw_subtype1
    On c.base_id = a.base_id
    ) j
    On j.base_id = xref.base_id
    -where j.base_id is not null
    ;

    / * Sample output:

    BASE_ID ORDER_ID
    ---------- ----------------
    2 101
    3 102

    2 selected lines.
    */

    -- --------------------------------------------------------
    -OK, the superfluous where clause seems to provide a means
    -to work around this problem
    --
    -Will be LEFT JOIN more the WHERE clause also works
    - as a workaround?
    -- --------------------------------------------------------
    Select
    XREF.base_id
    j.order_Id
    of kaw_ref xRef
    Join
    -left join
    (select
    a.base_id,
    COALESCE(b.order_Id, c.Order_Id) as Order_Id
    of kaw_base one
    Join kaw_subtype1 b left
    On b.base_id = a.base_id
    c left join kaw_subtype2
    -join kaw_subtype1 c on the left
    On c.base_id = a.base_id
    ) j
    On j.base_id = xref.base_id
    -- --------------------------------------------------------
    -Just comment on the WHERE clause:
    --
    -OK, this when the clause seems quite unnecessary.
    -However, for some unknown reason this where clause
    -must be included so that the select clause can
    -Returns the correct results
    --
    -Can anyone please tell me why when the clause is
    -necessary?
    -- --------------------------------------------------------
    where j.base_id is not null
    ;

    / * Sample output:

    BASE_ID ORDER_ID
    ---------- ----------------
    1
    2 101
    3 102
    4 103

    4 selected lines.
    */

    -- --------------------------------------------------------
    -The LEFT JOIN can also be used to circumvent this
    -publish; However, I prefer to avoid the kind of "from".
    de - facto' inner joins because they lead to questions
    -associated with what the original author intended.
    -in particular, the original author didn't intend to return
    -the data with an inner join or did the author really
    -intend to include the other ranks too, but make one
    -unusual coding error?
    --
    -Will use nested rather than using join syntax of
    -a table derived also solve this problem?
    -- --------------------------------------------------------
    Select
    XREF.base_id
    j.order_Id
    of kaw_ref xRef
    -join
    left join
    (select
    a.base_id,
    COALESCE(b.order_Id, c.Order_Id) as Order_Id
    of kaw_base one
    Join kaw_subtype1 b left
    On b.base_id = a.base_id
    c left join kaw_subtype2
    -join kaw_subtype1 c on the left
    On c.base_id = a.base_id
    ) j
    On j.base_id = xref.base_id
    -- --------------------------------------------------------
    -This where clause should be included to convert the
    -an outer join in an inner join "de facto".
    -- --------------------------------------------------------
    where j.base_id is not null
    ;

    / * Sample output:

    BASE_ID ORDER_ID
    ---------- ----------------
    1
    2 101
    3 102
    4 103

    4 selected lines.
    */

    -- --------------------------------------------------------
    -Unfortunately, move to the nested join syntax
    -do not in itself solves this problem.
    --
    -Added in the redundant WHERE clause will provide
    -a work around?
    -- --------------------------------------------------------
    Select
    XREF.base_id,
    COALESCE(b.order_Id, c.Order_Id) as Order_Id
    of kaw_ref xRef
    Join
    (kaw_base one
    Join kaw_subtype1 b left
    On b.base_id = a.base_id
    c left join kaw_subtype2
    On c.base_id = a.base_id
    ) on a.base_id = xref.base_id
    -- --------------------------------------------------------
    -This where clause should be included to convert the
    -an outer join in an inner join "de facto".
    -- --------------------------------------------------------
    -where j.base_id is not null
    ;

    / * Sample output:

    no selected line.
    */

    -- --------------------------------------------------------
    -Adding the redundant search where clause provides
    -something that causes this query works correctly.
    --
    -Is this a bug?
    -- --------------------------------------------------------
    Select
    XREF.base_id,
    COALESCE(b.order_Id, c.Order_Id) as Order_Id
    of kaw_ref xRef
    Join
    (kaw_base one
    Join kaw_subtype1 b left
    On b.base_id = a.base_id
    c left join kaw_subtype2
    On c.base_id = a.base_id
    ) on a.base_id = xref.base_id
    -- --------------------------------------------------------
    -This where clause must be included as a work around to
    -to ensure that the correct rows will be returned
    -- --------------------------------------------------------
    where a.base_id is not null
    ;

    / * Sample output:

    BASE_ID ORDER_ID
    ---------- ----------------
    1
    2 101
    3 102
    4 103

    4 selected lines.
    */

    Can someone tell me what exactly is going on with this?

    Hello

    Would be - this bug #9011590 "bad results due to the elimination of the join?
    He described as possibly a regression introduced with 11.1.0.7 patch set.

    Oracle Support says 11.2 is affected too, but I can't reproduce with your test case.

    Just in case, you could try one of the following workarounds?

    alter session set "_optimizer_join_elimination_enabled" = false;
    
    alter session set "_fix_control" = '6167716:OFF';
    
  • Join cfquery problem

    I had a problem when I try to join these 3 tables and count the records in the subquery. If anyone can provide assistance with this... thnx.

    SELECT DISTINCT *.
    ((StSupportTroubleTicket t
    LEFT JOIN stEmployee e ON e.Emp_ID = t.UsersID)
    LEFT JOIN stTTdiscussion d d.ttID = t.ID)
    WHERE t.complete = 0 AND t.project = 0
    ORDER BY DESC t.ID

    I'm counting the records of stTTdiscussion.

    (it is a support trouble ticket program that has a comment on the post article. I am a type 15 comments interface digg.com and I would like to know the number of comments in this post.)

    DB MSAccess, win2K3, MX 6.1

    > Adam, the query I have here doesn't work.

    Hmmm. well, it's a start. I imitated your DB locally and it works for
    Me too. It could have been because I was doing a mix of RIGHT and LEFT
    outer joins when I came across a problem with access, the last time.

    In any case, that's what you want:

    SELECT t.ID, count (d.ttID) as discussionCount
    ((StSupportTroubleTicket t
    LEFT JOIN stEmployee e ON e.Emp_ID = t.UsersID)
    LEFT JOIN stTTdiscussion d d.ttID = t.ID)
    WHERE t.complete = 0 AND t.project = 0
    GROUP BY t.ID
    ORDER BY DESC t.ID

    --
    Adam

  • Do not repeat with a LEFT JOIN QUERY question

    Hello

    I would like to know how to display the following results:
    *Name*:  John Fox
    *Sales:*  1- LAPTOP
                    2- HARDDRIVE
                    3- COMPUTER
    Here's my 2 tables: CUSTOMER and SALES
    CUSTOMER
    _________________
    
    ID NAME GENDER 
    1 John Mayer F 
    2 Melissa John F 
    3 Julie Black F 
    4 Mickael Fox M 
    5 John Fox M 
    
    SALES
    _________________________
    ID ID_CUSTOMER TYPE 
    1 1 Boat 
    2 1 TV 
    3 4 CD PLAYER 
    4 5 LAPTOP 
    5 5 HARDDRIVE 
    6 5 COMPUTER 
     
    My QUERY
    SELECT customer.Name as NAME, customer.Gender, sales.TYPE
    from customer
    LEFT JOIN sales
    ON customer.ID = sales.ID_CUSTOMER
    WHERE customer.Name = 'John Fox'
    The problem: if I use the default template, I have:
    NAME GENDER TYPE 
    John Fox M LAPTOP 
    John Fox M HARDDRIVE 
    John Fox M COMPUTER 
    I don't want the name of John Fox being repeated in each row.
    I tried to add: #Name # in the DEFINITION of the REGION - REGION HEADER, but I have this result:
    #NAME# 
    NAME GENDER TYPE 
    John Fox M LAPTOP 
    John Fox M HARDDRIVE 
    John Fox M COMPUTER 
     
    So, what can I do to get this result? Change the query?
    Name:  John Fox
    Sales: 1- LAPTOP
           2- HARDDRIVE
            3- COMPUTER
    Thank you

    Roseline

    Roseline salvation,

    You can adapt the solution suggested in this post Re: more than 1 records in a single cell

    Thank you
    Manish

  • Including only in rows on a left join

    Hi, consider the following (hypothetical example http://www.codinghorror.com/blog/archives/000976.html but a real problem more complex mirror I)

    create table test1 (identification number, name varchar2 (10), color varchar2 (10))
    create table test2 (identification number, name varchar2 (10), color varchar2 (10))

    insert into test1 values (1, 'pirate', 'black')
    insert into test1 values (2, 'monkey', 'black')
    insert into test1 values (3, 'ninja', 'black')
    insert into test1 values (4, 'spaghetti', 'black')


    insert into test2 values (1, 'Swede', 'black')
    insert into test2 values (2, 'pirate', 'red')
    insert into test2 values (3, 'darth', 'red')
    insert into test2 values (4, 'ninja', 'black')


    *****
    Running the following query left join as usual gives the expected result

    Select * from test1
    outer join test2 left test1.name = test2.name


    ID NAME ID NAME COLOR COLOR

    1 appropriate appropriate 2 black red
    3 black ninja 4 black ninja
    null null null 4 black spaghetti
    null null null 2 black monkey

    ****
    If I add a restriction on test2.colour, I lose the three rows...

    ID NAME ID NAME COLOR COLOR

    1 appropriate appropriate 2 black red

    1 selected lines

    ****
    I can get 2 of them by re - including NULL values...

    ID NAME ID NAME COLOR COLOR

    1 appropriate appropriate 2 black red
    null null null 4 black spaghetti
    null null null 2 black monkey

    3 selected lines

    But what I want is for the other row where test2.colour is black to come back that looks like this...

    ID NAME ID NAME COLOR COLOR

    1 appropriate appropriate 2 black red
    null null null 3 black ninja
    null null null 4 black spaghetti
    null null null 2 black monkey

    4 selected lines

    As you can see, rank test2.id = 4 is here with the id, name, and the null color. How can I do this?

    Thank you!
    :)

    Published by: user3809287 on 15-Sep-2008 03:56

    ****
    If I add a restriction on test2.colour, I lose the three rows...

    ID NAME ID NAME COLOR COLOR

    1 appropriate appropriate 2 black red

    1 selected lines

    No, you don't have to if you add the restriction to the join instead of a filter condition condition:

    Oracle9i Enterprise Edition Release 9.2.0.8.0 - Production
    With the Partitioning, OLAP and Oracle Data Mining options
    JServer Release 9.2.0.8.0 - Production
    
    Session altered.
    
    SQL>
    SQL> drop table test1;
    
    Table dropped.
    
    SQL> drop table test2;
    
    Table dropped.
    
    SQL>
    SQL> create table test1 (id number, name varchar2(10), colour varchar2(10));
    
    Table created.
    
    SQL> create table test2 (id number, name varchar2(10), colour varchar2(10));
    
    Table created.
    
    SQL>
    SQL> insert into test1 values (1, 'pirate','black');
    
    1 row created.
    
    SQL> insert into test1 values (2, 'monkey','black');
    
    1 row created.
    
    SQL> insert into test1 values (3, 'ninja','black');
    
    1 row created.
    
    SQL> insert into test1 values (4, 'spaghetti','black');
    
    1 row created.
    
    SQL>
    SQL> insert into test2 values (1, 'rutabaga','black');
    
    1 row created.
    
    SQL> insert into test2 values (2, 'pirate','red');
    
    1 row created.
    
    SQL> insert into test2 values (3, 'darth','red');
    
    1 row created.
    
    SQL> insert into test2 values (4, 'ninja','black');
    
    1 row created.
    
    SQL>
    SQL> commit;
    
    Commit complete.
    
    SQL>
    SQL> select * from test1
      2  left outer join test2 on test1.name = test2.name
      3  where test2.colour = 'red';
    
            ID NAME       COLOUR             ID NAME       COLOUR
    ---------- ---------- ---------- ---------- ---------- ----------
             1 pirate     black               2 pirate     red
    
    SQL>
    SQL> select * from test1
      2  left outer join test2 on test1.name = test2.name and test2.colour = 'red';
    
            ID NAME       COLOUR             ID NAME       COLOUR
    ---------- ---------- ---------- ---------- ---------- ----------
             1 pirate     black               2 pirate     red
             4 spaghetti  black
             3 ninja      black
             2 monkey     black
    
    SQL>
    

    You can read complete Gints Plivna notes on the joints here:

    http://www.gplivna.EU/papers/sql_join_types.htm

    Kind regards
    Randolf

    Oracle related blog stuff:
    http://Oracle-Randolf.blogspot.com/

    SQLTools ++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676 /.
    http://sourceforge.NET/projects/SQLT-pp/

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

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

  • 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',="">

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

Maybe you are looking for