Group of and outer joins

Hello

Some code someone else created under.

Group an in it and expected this group to 1 row as 2 lines in the table of titles titles_x_ref, but values in the group by the same clause.

When run the query below returns 2 rows but the columns in the colum group all of the same value.

Null value in two lines as well de.niss_ean.

What Miss me?

Using oracle 11.2.0.3

{code}

Select nvl(tx.new_branch_code,'BRA777') new_branch - bx.new_branch

min (BRIS_ISSUE_DAY)

min (BRIS_ISSUE_WEEK)

BRIS_ISSUE_YEAR

min (nvl (tx.new_title_code, bris_title_code)) BRIS_TITLE_CODE

min (BRIS_COST_PRICE)

min (BRIS_COVER_MOUNT_FLAG)

min (BRIS_TERMS_OF_SALE)

, coalesce (de.new_niss_ean, nvl2 (tx.new_title_code, t.titl_issue_frequency: lpad (tx.new_title_code, 6, '0'): substr (bris_issue_year, 3, 2) | lpad (bris_issue_week, 2, '0') |)) BRIS_ISSUE_DAY | ((' 01', i.bris_ean)) bris_ean

min (BRIS_INVOICE_DATE)

min (BRIS_BAR_CODE)

min (BRIS_OFFICIAL_ON_SALE_DATE)

min (BRIS_KEEP)

min (BRIS_VAT_CODE_CODE)

min (BRIS_REFERENCE)

min (BRIS_RECALL_DATE)

min (BRIS_ORDER_BY_DATE)

min (BRIS_ON_SALE_DATE)

min (BRIS_CLAIM_END_DATE)

min (BRIS_HANDLING_UNIT)

min (BRIS_HANDLING_ALLOWANCE)

min (BRIS_COVER_MOUNT_PRICE)

min (BRIS_CLAIM_START_DATE)

min (BRIS_NAPIER_REALLOC_FLAG)

min (BRIS_COVER_MOUNT_VAT_CODE)

min (BRIS_SUPPLEMENTS)

min (BRIS_LAST_CLOSED_TITLE_CODE)

min (BRIS_PUBLISHER_REFERENCE)

min (BRIS_DELETE_FLAG)

, min (coalesce (de.new_niss_ean, nvl2 (tx.new_title_code, t.titl_issue_frequency: lpad (tx.new_title_code, 6, '0'): substr (bris_issue_year, 3, 2) | lpad (bris_issue_week, 2, '0') |))) BRIS_ISSUE_DAY | (((' 01', i.bris_ean))) BRIS_LINK_EAN

min (nvl (BRIS_LINK_ISSUE_YEAR, bris_issue_year))

min (BRIS_LINK_RELIABILITY)

min (BRIS_NORMALISATION_RUN)

min (BRIS_YEAR_OF_PUBLICATION)

min (BRIS_DAILY_COLLECTION_FLAG)

sum (BRIS_TRADE_COUNTER_STOCK)

sum (BRIS_STOCK_TRANSFERS)

min (BRIS_TITLE_SOR_ALLOW_TYPE)

min (BRIS_TITLE_SOR_ALLOWANCE)

min (BRIS_ISSUE_STATUS)

sum (BRIS_CREDITS_CLAIMED_ELEC)

sum (BRIS_CREDITS_CLAIMED_MAN)

sum (BRIS_MANAGERS_CREDITS)

branch_issues I have

Join titles t

on i.bris_title_code = t.titl_code

titles_x_ref left join tx

on i.bris_title_code = tx.title_code

from dup_eans_x_ref left join

on de.niss_ean = i.bris_ean

and de.niss_issue_year = i.bris_issue_year

and de.niss_issue_week = i.bris_issue_week

and de.niss_issue_day = i.bris_issue_day

and de.new_title_code = tx.new_title_code

AND i.bris_branch_code in ('BRA888')

Group of de.new_niss_ean, nvl(tx.new_branch_code,'BRA777'), t.titl_issue_frequency, tx.new_title_code, bris_issue_year, bris_issue_week, BRIS_ISSUE_DAY, i.bris_ean, BRIS_ISSUE_YEAR

{code}

Hello

Thank you solved my particular problem.

Group by is behaving as expected, but on reason of inspection more close return 2 rows was 1 of the band sin value by clause having value of differenet between the lines, where the 2 rows.

Tags: Database

Similar Questions

  • Count (*) with Group of and a join

    I have the tables below:

    Tables:
    EMPLOYEE 
    EMP_ID         LNAME             FNAME
    1000                 SLITT              JOHN
    1001                 SLITHER              STEVE
    1002                 JACOB              MARLYN
    1003                 STUFFEY     NOSE
    1004                 SLIPPY              MOUTH
    -----
    ACCESS_TYPE
    ACCESS_TYPE_ID     ACCESS_DESCRIPTION
    1                         EMPLOYEE
    2                         EMPLOYEE_ADMIN
    3                         CONTRACTOR
    -----
    EMPLOYEE_ACCESS
    ACCESS_ID      ACCESS_TYPE_ID     EMP_ID     ACCESS_EFF_DATE     
    1               1               1000              01-JAN-13
    2               1               1001              10-FEB-13
    3               1               1002              18-FEB-13
    4               2               1003              10-OCT-12
    5               3               1004              10-MAR-08
    -----
    I'm trying to appear on the behalf of the Group of employees by their type and whose name does not begin with SL
    I wrote the following query and I get a missing Expression 00936. What I am doing wrong? Thank you

    SELECT EA. COUNT (*), ACCESS_TYPE_ID
    OF EMPLOYEE_ACCESS EA, USED E
    WHERE ACCESS_EFF_DATE > = 31 December 12 ' AND E.LNAME NOT LIKE '% SL.
    ACCESS_TYPE_ID GROUP;

    Published by: parsar on March 25, 2013 15:54

    >
    FAM COUNT (*)
    >
    You have a column named "COUNT" in your table? NOT! You probably intend to use the COUNT function: ditch the prefix aliases, functions use a prefix.
    >
    WHERE ACCESS_EFF_DATE > = 31 DECEMBER 12 '
    >
    Don't use strings to DATE values. Use the dates and the TO_DATE function if you need to convert a string to a date literal.

    This Cartesian join between the tables is unlikely to be what you want to do.

  • outer join and OR condition

    Hello world

    I have a query that is not working properly. I'm trying to join two tables and I or condition and outer join
    I get the error message
     ORA-01719: outer join operator (+) not allowed in operand of OR or IN
    
    my query is as follow
    
    SELECT l.* FROM table1 l, table2 map
    WHERE (NVL(l.id, '-99') = NVL(map.id(+), NVL(l.id, '-99'))
            AND  l.TYPE = 'TKE')
          ) OR 
        (NVL(l.id, '-99') = NVL(map.id(+), NVL(l.id, '-99'))
    AND NVL(l.type, '-99') = NVL(map.type(+), NVL(l.type, '-99'))
    AND NVL(l.pos_22, '-99') = NVL(map.pos_22(+),NVL(l.pos_22, '-99'))
    AND NVL(l.pos_27, '-99') = NVL(map.pos_27(+),NVL(l.pos_27, '-99'))
    AND NVL(l.pos_17, '-99') = NVL(map.pos_17(+),NVL(l.pos_17, '-99'))
    AND NVL(l.pos_18, '-99') = NVL(map.pos_18(+),NVL(l.pos_18, '-99'))
    AND NVL(l.pos_12, '-99') = NVL(map.pos_12(+),NVL(l.pos_12, '-99'))
    AND NVL(l.pos_16, '-99') = NVL(map.pos_16(+),NVL(l.pos_16, '-99'))
    AND NVL(l.pos_34, '-99') = NVL(map.pos_34(+),NVL(l.pos_34, '-99'))
    AND NVL(l.pos_43, '-99') = NVL(map.pos_43(+),NVL(l.pos_43, '-99'))
    AND NVL(l.pos_14, '-99') = NVL(map.pos_14(+),NVL(l.pos_14, '-99'))
    AND NVL(l.status_cd, '-99') = NVL(map.status(+),NVL(l.status_cd, '-99'))
    AND NVL(l.action_cd,'-99') = NVL(map.action_cd(+), NVL(l.action_cd,'-99'))
    AND NVL(l.sys,'-99') = NVL(map.sys(+), NVL(l.sys,'-99'))
    AND NVL(l.ind,'-99') = NVL(map.ind(+), NVL(l.ind,'-99'))
      )
    So, basically in the above query I say that if the type = "TKE" do not join on all columns of pos. If type is not TKE then do all the joints on all columns POS etc.
    How do I rewrite query so that I can use OR and the outer JOIN in the same query?

    Hello

    It is one of several good reasons to use the ANSI join syntax. Move all the join conditions in the clause on, not the WHERE clause, and you do not use the sign +.

    SELECT  l.*
    FROM           table1 l
    LEFT OUTER JOIN  table2 map  ON   (    NVL(l.id, '-99') = COALESCE (map.id, l.id, '-99')
                                        AND  l.TYPE = 'TKE'
                          )
                                 OR  (     NVL (l.id, '-99') = COALESCE (map.id, l.id, '-99')
                              AND   NVL (l.type, '-99') = COALESCE (map.type), l.type, '-99')
                         ...
    

    Instead of nesting the NVL statements, use COALESCE, as illustrated above. It is independent of the issue of the join.

  • Oracle: Use LEFT OUTER JOIN, but convert the data to an external list

    Hello, all,.

    I know it can be done; I just don't remember how I got it done, oh there are so many years.

    Assumes that the tables exist for groups and individuals.  People can belong to several groups.

    SELECT g.groupName, p.lastName || ', ' || p.firstName as fullName
    FROM groups g LEFT OUTER JOIN groupPersonAssociation gpa ON gpa.groupID = g.groupID
                  LEFT OUTER JOIN person p ON p.personID = gpa.personID
    ORDER BY g.groupName, fullName
    

    This gives us:

    Group One          Alpha, Daniel
    Group One          Bravo, Charles
    Group One          Charlie, Chuck
    Group Two          Beta, Alpha
    Group Two          Delta, Bonnie
    Group Three        Echo, Bunny
    Group Three        Golf, Samuel
    Group Three        November, Stan
    

    How word the SQL to get the data as:

    Group One          Alpha, Daniel | Bravo, Charles | Charlie, Chuck
    Group Two          Beta, Alpha | Delta, Bonnie
    Group Three        Echo, Bunny | Golf, Samuel | November, Stan
    

    V/r,

    ^_^

    I finally thought to it.  I was using incorrect keywords on Google.

    SELECT g.groupName, LISTAGG(p.lastName || ', ' || p.firstName,' | ') WITHIN GROUP (ORDER BY g.groupName) "fullName"
    FROM groups g LEFT OUTER JOIN groupPersonAssociation gpa ON ggpa.groupID = g.groupID
                  LEFT OUTER JOIN person p ON p.personID = gpa.personID
    GROUP BY g.groupName
    ORDER BY g.groupName, fullName  
    

    Just in case someone else is going through this same desire.

    HTH,

    ^_^

  • outer join on the aggregate query

    This is probably a relatively simple matter, as long as I explain it well enough:

    I have two tables:

    categorycodes and properties

    categorycodes is a lookup table.

    both tables have a catcode field which is a char (1) that contains matching data (only the numbers 1 to 6)

    CREATE

    TABLE CATEGORYCODES

    (

    CATCODE CHAR (1 BYTE) NOT NULL,

    DESCRIPTION VARCHAR2 (25 BYTE) NOT NULL,

    CONSTRAINT CATEGORYCODES_PK PRIMARY KEY (CATCODE) ALLOW

    )

    catCode

    1

    2

    3

    4

    5

    6

    The properties table has approximately 600 000 records. The properties table also has a field named parcelno which is a tank (9).  It contains a string of figures and numbers only.

    What I would like is:

    catCode, count (*)

    1 580

    2 300

    3 3000

    4 235

    5 0

    6 80

    I limited the results of the query to make sure it was a game that would not all catcodes in it.  I have trouble to get the one with zero to display.  I know that this has to do with how I do the join, but I don't know what.

    It is a sample of what I've tried:

    Select i.

    Of

    (select catcode, count (*)

    property p

    where substr (parcelno, 1, 3) = ' 871 "

    Catcode group) i

    outer join right categorycodes cc

    We i.catcode = cc.catcode;

    I'm not worried about the situations where catcode is null in the properties.  Parcelno cannot be null.

    Hello

    Looks like your query should work; except that you won't COUNT (*); That would make each issue at least 1.  COUNT (*) means that count the total number of lines, no matter what is on them, so he'll see the line with just the catcode of the lookup table that matches nothing and which count as 1.  You want to count the number of rows in the table of properties, so expect a column of the properties that cannot be NULL.

    Here is a slightly different way

    SELECT c.catcode

    EARL of (p.catcode) AS cnt

    OF categorycodes c

    P ON p.catcode = c.catcode LEFT OUTER JOIN properties

    AND SUBSTR (p.parcelno

    1

    3

    ) = ' 871 "

    ;

    If the condition about 871' ' part of the join condition, then you don't need a subquery.

    .

    I hope that answers your question.
    If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and also publish outcomes from these data.
    Point where the above statement is erroneous results, and explain, using specific examples, how you get the right result of data provided in these places.

    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: https://forums.oracle.com/message/9362002

  • My Confusion of outer join

    Oracle 10g

    I have three below queries that use the outer join syntax.

    All three queries return exactly the same results


    (a)
    SELECT TA.ID TA
         , TB.ID TB
      FROM TA
         , TB
     WHERE TA.ID = TB.ID(+);
    (b)
    SELECT TA.ID TA
         , TB.ID TB
      FROM TA
         , TB
     WHERE TB.ID(+) = TA.ID;
    (c)
    SELECT TA.ID TA
         , TB.ID TB
      FROM TA
      LEFT OUTER JOIN TB ON TA.ID = TB.ID;
    I have the right call outer join query because the (+) sign is located on the right and outer join query (b) left because the (+) sign is on the left?

    Or is the left join or right determined by the join columns specified in the order select it?



    Create the Script
    CREATE TABLE TA
      (
        "ID" NUMBER
      );
    
    CREATE TABLE TB
      (
        "ID" NUMBER
      );
    
    INSERT INTO TA (ID) VALUES ('1');
    INSERT INTO TA (ID) VALUES ('2');
    INSERT INTO TA (ID) VALUES ('3');
    
    INSERT INTO TB (ID) VALUES ('1');
    INSERT INTO TB (ID) VALUES ('2');
    INSERT INTO TB (ID) VALUES ('4');
    Ben

    Published by: benton on August 15, 2012 08:16

    Hi, Ben.

    Benton says:
    ... So is it correct to say that the left or right refers to which side the null values will be displayed?

    Lol it is incorrect to say that the old syntax outer join (using the sign +) is either a left - or a right outer join.

    ... So I need to have the order of the columns in the correct SELECTION so that there is no likelihood of confusion over which side will display NULL values. If I place the columns A and B in the wrong order, that is to say B then a I'll lend to confusion about what will be returned with respect whether left or right.

    No, do not hesitate to organize columns in the select in any way will help your users the most. What is happening in the FROM and WHERE clause, in particular the order in which the tables happens to appear, may not have something to do with the order of the columns in the output.
    Many readers are more comfotable with having NULL columns at the end of a line of output, or at least not at the beginning, so maybe it's one of the reasons for ta.id first in your example. Rearrange the columns in the game any way more than makes sense for people who will look at them.

  • using (+) or left outer join

    Dear Expert;

    I've been playing by using the two symbol... and realized that they do the same thing... Is it true...? or am I wrong.

    Thank you.

    Hello

    user13328581 wrote:
    Dear Expert;

    I've been playing by using the two symbol... and realized that they do the same thing... Is it true...? or am I wrong.

    They all have two outer joins. The + rating was the original way to do it in Oracle. LEFT, RIGHT, and FULL OUTER JOIN introduced in Oracle 9, but the old way is still supported.

    There are some situations (such as an outer join complete and outer-join a table to two different tables) that are better with the ANSI syntax (it's LEFT OUTER JOIN). It is possible to get the same results using +, but it must be combersome and/or inefficient workarounds. I suggest that you use always LEFT OUTER JOIN (or FULL OUTER JOIN, or, on occasions RIGHT OUTER JOIN). I think that you will find it easier and less error-prone.

  • Oracle 8i outer join

    The following query is supposed to return all the rows in kpi_reports where the conditions are met and its values corresponding to kpi_master and kpi_report_requests, where the values exist. However, it only returns the lines containing the values kpi_report_request, doing so as an inner join.

    SELECT kr.report_id, kr.report_name, kr.kpi_id, km.kpi_description, krr.requested_date
    OF kpi_reports kr, kpi_master km, kpi_report_requests krr
    WHERE kr.kpi_id = km.kpi_id
    AND kr.dsp_id = 9
    AND kr.report_name IS NOT NULL
    AND kr.report_id = krr.report_id (+)
    AND krr.dealer_id = 26402
    ORDER BY kr.report_name

    I have reviewed a number of tutorials online brush upward on this thus shown a colleague, and I think Miss me something, maybe you can not do an inner join and outer join in the same query? Don't seem to make sense to me, but all the examples I've seen consist of two tables with an outer join.

    Thanks in advance!

    Something like this maybe? (Not sure about Oracle 8, but I do similar things in 9i)

    Phil

  • Complex Inner Join and outer subquery where clause to join internal?

    The DDL for this post was too big and I had to put on my site:
    http://www.harbortownsolutions.com/DDLForDORTable.txt

    My goal is to create a report of sales data for 116 stores containing daily sales and count of comments in recent years. My challenge is that I am pulling data from the same table, but with different dates to get data from last year and the week in data from date of last year.


    The dates used for reports are:

    SalesDate = 06/04/2009
    SalesDateForLastYear = 2008-06-05
    SalesDateBeginningOfWeek = 01/06/2009
    SalesDateBginningOFWeekLastYear = 2008-06-02

    PSEUDOQUERYS:
    ---======= DOLLAR VARIANCE = You Said you have $100 worth of meat(inventory) but you only have $50 worth of meat
    SELECT 
        BUSI_DATE as BusinessDate, 
        ORACLE_KEY as StoreID,
        FIELD1  as Sales,
        FIELD2  as GuestCount,
        FIELD3  as DollarVariance,
        FIELD4  as Cars
    FROM MYDAILYTOTALS
    WHERE Busi_date = SalesDate
       AND ORACLE_KEY IN (SELECT StoreID From MyStores); 
    -======= ONLY Guest count and Sales are needed in comparisons against last year    
    ---======    Last YEar dates = corresponding dates for this year ie Tuesday of this 
    week matched to Tuesday of last year (except for leap year)
    SELECT 
        ORACLE_KEY as StoreID
        FIELD1  as SalesLastYear
        FIELD2  as GuestCountLastYear   
    FROM MYDAILYTOTALS
    WHERE Busi_date = SalesDateForLastYear 
       AND ORACLE_KEY IN (SELECT StoreID From MyStores);
           
    
    SELECT 
        ORACLE_KEY as StoreID
        SUM(FIELD1)  as WeekToDateSales
        SUM(FIELD2)  as WeekToDateGuestCount  
    FROM MYDAILYTOTALS
    WHERE Busi_date BETWEEN SalesDateBeginningOfWeek and SalesDate
       AND ORACLE_KEY IN (SELECT StoreID From MyStores) 
    GROUP BY ORACLE_KEY 
       --=======  
    SELECT 
        ORACLE_KEY as StoreID
        SUM(FIELD1)  as WeekToDateSalesLastYear
        SUM(FIELD2)  as WeekToDateGuestCountLastYear  
    FROM MYDAILYTOTALS
    WHERE Busi_date BETWEEN SalesDateBeginningOfWeekLastYear and SalesDateLastYear
       AND ORACLE_KEY IN (SELECT StoreID From MyStores) 
    GROUP BY ORACLE_KEY   
    Question: Since they all use the same store of nbrs, I specify on each request? Can't I just specify only once on outer query Where clause?

    Also, how would fit the following of HOEK script:
    See how I put 1 field based on another field value

    He reads a record for each store of 116 stores in the database. There are 2 situations that have been addressed by Hoeks code:
    For each of the 116 stores in the store table, there must be 1 and only
    registration of 1 stock to match the record of MyStoreTotals. However, sometimes there is no record of inventory.
    and sometimes there will be 2 (in a case where a manager of database updates)
    After daily treatment) files. If so, the record with Is_posted = 1
    is the one that should be included in the query. The following text accomplishes this:
    -chr (39) is the single quote
     Select StoreId, 
             DollarVariance 
      from   (select store.storeid, 
                       case
                              when inv.storeid is null then 'None'
                              when inv.is_posted = 0 then 'NP'
                              else chr(39)||inv.total_dol_var||chr(39)
                        end as DollarVariance, 
                        row_number() over (partition by store.storeid order by inv.is_posted desc) rn  
                   from  myInven inv 
                   right outer join mystores  store
                                  on store.storeid = inv.fk_str_main_id
                                  and inv.busi_date = to_date(SalesDate, 'dd-mon-yyyy'))
          where rn = 1;      
    Can I put this request on the place where clause of the outer to query I put on a JOIN clause?

    So I guess that's why you used the MAX.

    That is right.
    I used CASES to identify and complete the necessary columns since the first set of results (WITH).
    So then I more or less "swivels somehow" lines of this result set to the columns, each store will appear once the most.

  • left and right outer join

    Hi gurus,

    Left outer join:

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

    Select * from A LEFT OUTER JOIN B on A.col = B.col;

    by definition, a left outer join brings the rows that match the join condition and lines not corresponding to table A.

    My question here is "corresponding to B and no matching rows in A" is that nothing, but... SELECT * FROM A;

    can someone pls clarity...

    Thank you.

    Imagine that you had:

    TableA

    COLUMN1 COLUMN2

    'A'                1

    'B'                2

    'C'                3

    TABLEB

    COLUMN1 COLUMN2

    'A'                 'X1'

    'A'                 'X2'

    'B'                 'Y'

    'D'                 'Z'

    SELECT * FROM TABLEA;

    A 1

    B 2

    C 3

    Now, if you want to join (first column is either in table A or B, (deuxieme from tableA, third table B)

    SELECT * FROM TABLEA A JOIN TABLEB B ON (A.COLUMN1 = B.COLUMN1)

    A 1 X 1

    A 1 X 2

    B 2 Y

    SELECT * FROM TABLE LEFT B EXTERNAL ON (A.COLUMN1 = B.COLUMN1) JOIN TABLE

    A 1 X 1

    A 1 X 2

    B 2 Y

    C 3 {null}

    SELECT * FROM TABLE A TABLE RIGHT OUTER JOIN B (A.COLUMN1 = B.COLUMN1)

    A 1 X 1

    A 1 X 2

    B 2 Y

    D {null} Z

    SELECT * FROM TABLE A TABLE FULL OUTER JOIN B (A.COLUMN1 = B.COLUMN1)

    A 1 X 1

    A 1 X 2

    B 2 Y

    C 3 {null}

    D {null} Z

    HTH

  • Outer joins are equijoins and?

    Manual says Yes, but I think their only equijoins, insofar as the matched data and include other data as well. so technically should not fall outside the category of the equijoins?

    Hello

    Outer joins can be are equijoins.  In other words, some outer joins are of equijoins, others are not.

  • Outer joins and null in the 'where' clause condition

    Hi people,

    Please help me on this.

    Here's my query.

    with x

    (select 'a' as a dual union all col1)

    Select 'b' as col1 of union double all the

    Select 'c' as double col1

    ),

    y as

    (

    Select 'b' as col2 from dual Union all the

    Select 'c' as col2 from dual Union all the

    Select would be "as col2 from dual Union all the"

    Select 'e' as col2 from dual

    )

    Select * x y right outer join

    on x.col1 = y.col2 and y.col2 is null

    Get all the lines of 'COL1' as null. Why like this?

    Just add the condition to the WHERE clause for example

    WITH x AS
    (SELECT 'a' AS col1 FROM dual UNION ALL
    SELECT 'b' AS col1 FROM dual UNION ALL
    SELECT 'c' AS col1 FROM dual
    ),
    y AS
    (
    SELECT 'b' AS col2 FROM dual UNION ALL
    SELECT 'c' AS col2 FROM dual UNION ALL
    SELECT 'd' AS col2 FROM dual UNION ALL
    SELECT 'e' AS col2 FROM dual
    )
    SELECT * FROM x LEFT OUTER JOIN y
    ON x.col1=y.col2                     ----want to add "and y.col2 is null " condition to get value "a"
    where y.col2 is null
    
  • left outer join and the where clause for the table to the right

    I want to join two tables a and b, where a is a must and b is a result set in option. When I use a left outer join to a to b, I want to achieve:

    1. Select a single column, two columns of b (not the join columns)
    2 - even if theres no friendly on the join column does not return data from one.
    3. If there is a match applies when the criteria on column b (table in option)

    so, how can I avoid no_data_found in this case? When I apply where criteria for b, so it does not return the data from one, which is a must.

    Sounds like a regular outer join to me...

    select a.col1, b.col2, b.col2
    from   tableA a
           left outer join tableB b
           on (a.id = b.id and b.colX = 'X')
    
  • Outer Join and joining several Tables

    Hello

    Oracle Database 10 g Express Edition Release 10.2.0.1.0 - product

    I have three tables AddProject, AssociateProjectLead, AddAssociate. Now I'm generating a report who will join AddProject and AssociateProjectLead for a list of all the projects, even if it doenst have a project coordinator. I used the outer join for this. However, if I want the name of the project leader, I need to search for AddAssociate table. By joining this table also, the outer join is no longer valid. Please see the result below

    CREATE TABLE  "ADDPROJECT" 
       (     "VERSIONNO" NUMBER(*,0), 
         "PROJID" VARCHAR2(20), 
         "PROJNAME" VARCHAR2(60), 
         "PROJSTARTDATE" DATE, 
         "PROJSTATUS" VARCHAR2(20), 
         "PROJENDDATE" DATE, 
         "PROJENDTYPE" VARCHAR2(20), 
         "PROJENDREASON" VARCHAR2(1000), 
         "UCPROJECTMANAGER" VARCHAR2(20), 
         "FROMDATE" DATE, 
         "TODATE" DATE, 
         "SRCHFIELD" VARCHAR2(20), 
         "OPERATOR" VARCHAR2(20), 
         "PARENTPROJID" VARCHAR2(20), 
         "PROJHIDDENDATE" VARCHAR2(20), 
          CONSTRAINT "PK_B36" PRIMARY KEY ("PROJID", "PROJHIDDENDATE") ENABLE
       )
    
    
    CREATE TABLE  "ADDASSOCIATE" 
       (     "VERSIONNO" NUMBER(*,0), 
         "ASSOCIATEID" NUMBER(9,0) NOT NULL ENABLE, 
         "ASSOCIATENAME" VARCHAR2(100) NOT NULL ENABLE, 
         "CTOJOINDATE" DATE, 
         "STATUS" VARCHAR2(20), 
         "ENDDATE" DATE, 
         "SRCHFIELD" VARCHAR2(20), 
         "OPERATOR" VARCHAR2(20), 
         "FROMDATE" DATE, 
         "TODATE" DATE, 
          CONSTRAINT "PK_B23" PRIMARY KEY ("ASSOCIATEID") ENABLE
       )
    
    CREATE TABLE  "ASSOCIATEPROJECTLEAD" 
       (     "VERSIONNO" NUMBER(*,0), 
         "PROJLEADASSOID" NUMBER(9,0), 
         "PROJID" VARCHAR2(20), 
         "ASSOCIATEID" NUMBER(9,0), 
         "PROJLEADSTARTDATE" DATE, 
         "STATUS" VARCHAR2(20), 
         "ASSOCPROJHIDDENDATE" VARCHAR2(20), 
         "PROJHIDDENDATE" VARCHAR2(20), 
         "ENDDATE" DATE, 
          CONSTRAINT "PK_B40" PRIMARY KEY ("ASSOCIATEID", "PROJID", "ASSOCPROJHIDDENDATE") ENABLE
       )
    
    
    elect ap.projid,apl.associateid
    from addproject ap, associateprojectlead apl
    where ap.projid = apl.projid(+)
    and ap.projhiddendate = apl.projhiddendate(+)
    
    
    PROJID ASSOCIATEID 
    Proj08 75825 
    Proj09 75825 
    Proj10 75825 
    Proj11 75825 
    Proj12 259811 
    Proj01 103035 
    Proj02 103035 
    Proj03 320092 
    Proj04 320092 
    Proj05 120974 
    Proj06 367393 
    Proj07 117618 
    Proj07 224882 
    Proj07 246652 
    prj001 -  
    prj001 -  
    
    16 rows returned in 0.00 seconds
    
    
    select ap.projid,apl.associateid,aa.associatename
    from addproject ap, associateprojectlead apl,addassociate aa
    where ap.projid = apl.projid(+)
    and ap.projhiddendate = apl.projhiddendate(+)
    and apl.associateid = aa.associateid
    
    
    PROJID ASSOCIATEID ASSOCIATENAME 
    Proj11 75825 Amarendra Kumar Singh 
    Proj10 75825 Amarendra Kumar Singh 
    Proj09 75825 Amarendra Kumar Singh 
    Proj08 75825 Amarendra Kumar Singh 
    Proj02 103035 Rajesh Jayaprakash 
    Proj01 103035 Rajesh Jayaprakash 
    Proj07 117618 Chetan Malhotra 
    Proj05 120974 Perumal Rajaram 
    Proj07 224882 Dilshad Ahmad 
    Proj07 246652 Shankar Kausley 
    Proj12 259811 Arunchandar Arun Vasan 
    Proj04 320092 Venkatesh Sarangan 
    Proj03 320092 Venkatesh Sarangan 
    Proj06 367393 Venkata Ramakrishna P 
    
    14 rows returned in 0.00 seconds
    How can I select all the values in table AddProject?

    Published by: Pramukh on August 23, 2012 12:18

    Hello

    I could get the result with a bit of modification

    select ap.projid,
           apl.associateid,
           aa.associatename
      from addproject ap
           left outer join
           associateprojectlead apl
        on ap.projid = apl.projid
       and ap.projhiddendate = apl.projhiddendate
           left outer join
           addassociate aa
        on apl.associateid = aa.associateid
    

    As a follow-up, I have a request more. In the report form, the user can select a particular project ID and the report should be generated as a result. For example;-he wants to see the results of the only "Proj08". I get the output as below, while the result should display only the details of 'Proj08 '.

    select ap.projid,
           apl.associateid,
           aa.associatename
      from addproject ap
           left outer join
           associateprojectlead apl
        on ap.projid = apl.projid
       and ap.projhiddendate = apl.projhiddendate
       and ap.projID = 'Proj08'
           left outer join
           addassociate aa
        on apl.associateid = aa.associateid
    ORDER BY ap.projID
    
    PROJID ASSOCIATEID ASSOCIATENAME
    Proj01 -  -
    Proj02 -  -
    Proj03 -  -
    Proj04 -  -
    Proj05 -  -
    Proj06 -  -
    Proj07 -  -
    Proj08 75825 Amarendra Kumar Singh
    Proj09 -  -
    Proj10 -  -
    Proj11 -  -
    Proj12 -  -
    prj001 -  -
    prj001 -  -  
    
  • What is the difference between NOT IN and LEFT OUTER JOIN

    Hello

    I searched the difference between everywhere. But his powerlessness.
    Please tell me the differences.

    Thanks in advance
    KVB

    It's like comparing apples and oranges.

    NOT IN - exclude all lines matching the condition NOT IN (beware of NULL values).

    JOIN EXTERNAL - return of rows from the inner table even if there is no corresponding row in the outer table.

    SQL> -- NOT IN
    SQL> with x as
      2  (select 1 col1 from dual union all
      3   select 2 col1 from dual union all
      4   select 3 col1 from dual)
      5  ,    y as
      6  (select 1 col1 from dual)
      7  select *
      8  from   x
      9  where  col1 not in (1,2);
    
          COL1
    ----------
             3
    
    SQL> -- NOT IN (subquery)
    SQL>
    SQL> with x as
      2  (select 1 col1 from dual union all
      3   select 2 col1 from dual union all
      4   select 3 col1 from dual)
      5  ,    y as
      6  (select 1 col1 from dual)
      7  select *
      8  from   x
      9  where  col1 not in (select col1 from y);
    
          COL1
    ----------
             2
             3
    
    SQL> -- OUTER JOIN
    SQL> with x as
      2  (select 1 col1 from dual union all
      3   select 2 col1 from dual union all
      4   select 3 col1 from dual)
      5  ,    y as
      6  (select 1 col1 from dual)
      7  select *
      8  from   x
      9  left outer join
     10         y
     11  on x.col1 = y.col1;
    
          COL1       COL1
    ---------- ----------
             1          1
             3
             2
    
    SQL> -- Maybe it helps to contrast LOJ with just JOIN?
    SQL> with x as
      2  (select 1 col1 from dual union all
      3   select 2 col1 from dual union all
      4   select 3 col1 from dual)
      5  ,    y as
      6  (select 1 col1 from dual)
      7  select *
      8  from   x
      9  join   y
     10  on x.col1 = y.col1;
    
          COL1       COL1
    ---------- ----------
             1          1
    
    SQL> 
    

Maybe you are looking for