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

Tags: Database

Similar Questions

  • SSRS for lack of outer join with the Oracle data source

    It seems to be a problem with the Oracle driver used in the Reporting SERVICES query designer.

    When you use an Oracle data source, if I create an outer join in the graphic designer, it automatically inserts '{OJ' before the join and '} ' after her.  This is an incorrect syntax for Oracle and refuses to start.  The curly braces and the JO editable in designer text, but if I go back to the graphic designer and immediately to reintegrate them.

    Only, this has started to happen a year or two ago - before that it worked, but with the old (+) syntax.

    Can it not be healed?  It makes things very difficult.

    -Geoff

    Hi Geoff,

    Thanks for posting in the Microsoft Community.

    However, the question you posted would be better suited in the Forums of the Oracle Support; We recommend that you post your query in Oracle Support Forums to get help:

    https://forums.Oracle.com/forums/main.jspa;JSESSIONID=8d92100c30d8fb401bcbd10b46c38c9ddf1a3242549a.e34SbxmSbNyKai0Lc3mPbhmSc3aNe0? CategoryID = 84

    If you have any other questions or you need Windows guru, do not hesitate to post your questions and we will be happy to help you.

  • Outer join on the Filter Condition

    Hello

    I would like to show all rows in a query for two conditions to filter on the 'status '. I used an outer join on the outer query to return the values inside the inline query, but it returns not to return all rows.

    create table (test)
    ID number,
    start_date date,
    status varchar2 (1).
    number of amount,
    number of cust_type
    );


    Insert test values (001, June 1, 2014 ", am ', 189, 78");
    Insert test values (001, March 26, 2014 ", 'R', 175, 4");
    Insert test values (001, December 1, 2014 ", 'R', 89, 91");
    Insert test values ("001, 13 August 2014 ', 'J', 19, 2);
    Insert test values (001, 12 August 2014 ', 'E', 19, 2);

    Insert test values (002, January 1, 2014 ', 'R', 17, 4);
    Insert test values (002, 26 June 2014 ", 'R', 175, 4");
    Insert test values (' 002, February 1, 2014 ', 'J', 9, 8);
    Insert test values (002, 13 October 2014 ', ', 190, 2);

    Insert test values (' 003, June 1, 2014 ', 'J', 189, 78);
    Insert test values (003, March 26, 2014 ", 'R', 175, 4");
    Insert test values (003, December 1, 2014 ", 'R', 89, 91");
    Insert test values (' 003, 13 August 2014 ', 'J', 19, 2);
    Insert test values (' 003, 12 August 2014 ', 'J', 19, 2);

    commit;

    Select i.ids, i.start_date, i.cust_type, i.amount as gross_amount, i.amount + ii.amount as net_amount
    test I have,
    (select id, amount)
    of the test
    where (status = status or 'R' = 'J')) ii
    where i.cust_type in (4, 78, 91, 2, 4, 8)
    and i.ids (+) = ii.ids
    and i.status (+) to (', 'E')
    "and i.start_date between 1 January 14 ' and 31-dec-2014."

    The query above exclude ID 003 because there is that no status (M / E) butI want always display all codes, even if the condition is not consistent

    Hello

    Want results from an inner join to match identifiers, but the results of an outer join for identifiers that are not?  In other words, you want to include the rows of the table I only when one of the following is true:

    The line of table I have ticked all the boxes, or

    No line in not table i with the same ID meets all conditions

    ?

    If so, here's a way to do it:

    WITH got_rnk AS

    (

    Select i.ids, i.start_date, i.cust_type

    , nvl2 (ii.ids, i.amount, 0) as gross_amount

    , i.amount + nvl (ii.amount, 0) as net_amount

    dense_rank () over (partition of i.ids

    order of nvl2 (ii.ids, 'A', 'B')

    ) as rnk

    I have test

    (in left outer join

    SELECT ID, amount

    of the test

    where status ('R', 'J')

    ) ii on i.ids = ii.ids

    and i.cust_type in (4, 78, 91, 2, 4, 8)

    and i.start_date between to_date (January 1, 2014 ", 'dd-mon-yyyy')

    and to_date (31-dec-2014', 'dd-mon-yyyy')

    and i.status in (', 'E')

    )

    SELECT ID, start_date, cust_type

    gross_amount, net_amount

    of got_rnk

    where rnk = 1

    ;

    Results of your sample data:

    ID START_DATE GROSS_AMOUNT NET_AMOUNT CUST_TYPE

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

    1 1 June 2014 78 189 364

    1 1 June 2014 78 189 278

    1 1 June 2014 78 189 208

    1 12 August 2014 2 19 38

    1 12 August 2014 2 19 108

    1 12 August 2014 2 19 194

    2 13 October 2014 2 190 207

    2 13 October 2014 2 190 365

    2 13 October 2014 2 190 199

    3 March 26, 2014 4 0 175

    3 1 June 2014 78 0 189

    3 12 August 2014 2 0 19

    3 August 13, 2014 2 0 19

    3 1 December 2014 91 0 89

  • outer join in the view criteria

    Hello world

    I use jdeveloper 11.1.1.6.0

    I want to create outer join in the view criteria, so I had to substitute getCriteriaItemClause ViewObjImpl.java method

    my query is like this:

    SELECT t1. row_no, t2.type FROM table_1 t1, t2 from table_2

    WHERE t1. row_no (+) = t2. row_no

    and t1.user_Id (+) =: bindVar

    table_1 (row_no, user_Id)

    table_2 (row_no, type)

    the part " t1.user_Id (+) =: bindVar " should be put in the display criteria

    the method:

    @Override

    public String getCriteriaItemClause (ViewCriteriaItem viewCriteriaItem) {}

    String newQeury = this.getEntityDef (0) .getAliasName () + "." + viewCriteriaItem.getColumnName () + "(+) =:bindVar .

    Return newQeury;

    }

    but when I run the criteria see exception below raises:

    oracle.jbo.expr.JISyntaxError: Houston-36000: an unexpected token expression is found.

    When I remove the sign "(+)" of newQeury

    String newQeury = this.getEntityDef (0) .getAliasName () + "." + viewCriteriaItem.getColumnName () + "=:bindVar .  remove the sign "(+)" before =:bindVar

    raises the exception below

    Houston-29000: Unexpected exception caught: oracle.jbo.expr.JIEvalException, msg = Houston-25077: t1 name not found in the given object: ViewRow [[5-1-5] oracle.jbo.Key].

    Habib

    This is a duplicate of https://forums.oracle.com/thread/2577092

    Please do not post your questions several times.

    A possible solution posted to the original thread.

    Timo

  • using outer joins if the two column is null? Use only (+)

    Hi all

    create the table xxc_tr_num (tl_number number, tr_no number tl_no_id);

    insert into xxc_tr_num values (123,100,222);

    insert into xxc_tr_num values (124,100,333);

    create the table xxc_od_tab (tl_number number, tl_id number);

    insert into xxc_od_tab values (123,001);

    insert into xxc_od_tab values (null, null);

    create table xxc_oth_tab (name varchar2 (10), number of tl_id);

    insert into xxc_oth_tab values('abc',,001);

    insert into xxc_oth_tab values (null, null);

    Wait it out put

    tr_no tl_no_id name

    100 222 abc

    100 333

    using outer joins if the two column is null? use only please of outer joins

    And I tried to use outer joins on both tl_id column but not get values and I use have County (tr_no ) > 1

    Rajesh123 wrote:

    Thank you Kiss it is not possible to use having clause?

    You need to understand the functioning of the group. If you will not be asked this question.

    Check this box

    SQL> select tr_no,
      2         tl_no_id,
      3         count(*)
      4    from xxc_tr_num a,
      5         xxc_od_tab b,
      6         xxc_oth_tab c
      7   where a.tl_number = b.tl_number(+)
      8     and b.tl_id = c.tl_id(+)
      9   group
     10      by tr_no
     11       , tl_no_id;
    
         TR_NO   TL_NO_ID   COUNT(*)
    ---------- ---------- ----------
           100        333          1
           100        222          1
    

    See what returns the count? You have grouped according to TR_NO and TL_NO_ID. You must take into consideration the TL_NO_ID just put COUNT (TR_NO) does not increase the NUMBER of the whole group. To get the NUMBER on the whole group, I used the analytical function and did. Like this, see the number of the analytical function here

    SQL> select tr_no,
      2         tl_no_id,
      3         count(*),
      4         count(*) over(partition by tr_no)
      5    from xxc_tr_num a,
      6         xxc_od_tab b,
      7         xxc_oth_tab c
      8   where a.tl_number = b.tl_number(+)
      9     and b.tl_id = c.tl_id(+)
     10   group
     11      by tr_no
     12       , tl_no_id;
    
         TR_NO   TL_NO_ID   COUNT(*) COUNT(*)OVER(PARTITIONBYTR_NO)
    ---------- ---------- ---------- ------------------------------
           100        222          1                              2
           100        333          1                              2
    

    So to answer your question, yes you can't do in the HAVING clause...

  • How to specify an outer join in the query designer

    I quickly built a large query with the query designer, and it works very well, but does not produce 9 disks on 2200 - so I need to change to an outer join.

    My problem is that I can't find a way to specify an outer join. I tried to change the query, query builder formed, but it won't let me.

    I know that I can capture the query, edit and run it in sql developer and that works fine, but I want to use the Query Builder as it is the fastest way I know to quickly add and remove items - my users don't know exactly what that it to include.

    I know it's kind of a trivial question, but I searched the forum, manual, the web and no luck

    Thanks for any help you can give

    Glenn

    Hi Glenn,.

    When you use the query designer to create the sql statement, you must click on the empty box to the right of the fields in each table to create the join. When you are finished, you should see a line drawn between the two tables. Click on this line, and a small window appears allowing you to select inner outer or right outer joins, left.

    When the report was created, however, you must change the statement. For example, if you use the query designer to join DEPT at EMP based on the DEPTNO field on the two tables, you get:

    select      "DEPT"."DEPTNO" as "DEPTNO",
          "DEPT"."DNAME" as "DNAME",
          "DEPT"."LOC" as "LOC",
          "EMP"."EMPNO" as "EMPNO",
          "EMP"."ENAME" as "ENAME",
          "EMP"."JOB" as "JOB",
          "EMP"."MGR" as "MGR",
          "EMP"."HIREDATE" as "HIREDATE"
     from      "EMP" "EMP",
          "DEPT" "DEPT"
     where   "DEPT"."DEPTNO"="EMP"."DEPTNO"
    

    This is to change:

    select      "DEPT"."DEPTNO" as "DEPTNO",
          "DEPT"."DNAME" as "DNAME",
          "DEPT"."LOC" as "LOC",
          "EMP"."EMPNO" as "EMPNO",
          "EMP"."ENAME" as "ENAME",
          "EMP"."JOB" as "JOB",
          "EMP"."MGR" as "MGR",
          "EMP"."HIREDATE" as "HIREDATE"
     from      "EMP" "EMP"
          LEFT OUTER JOIN "DEPT" "DEPT" ON "DEPT"."DEPTNO"="EMP"."DEPTNO"
    

    Andy

  • Outer joins to the left... Please help!

    Hmm. Ive had trouble with this one for a while and have read and re-read docs etc.

    IM under 11.2 XE and its Apex 4.2 application...

    Its a simple query with outer joins... but I can't simply to do it right after several hours of trying! ID be very grateful if anyone can lend a hand...

    For the query below. I am looking for the following:

    Complete list of entities, a sum of the values if they exist (and obviously empty if they don't), filtered by a table of SUM choice only the records that match a value in the lookup table.

    Select

    e.ENTITY as ENTITY,

    Sum (p.amount) as Forecast_Income,

    Sum (BR.bri_credit) as Actual_Income,

    Sum (BR.bri_debit) as Actual_Expenses

    Of

    e entities

    LEFT OUTER JOIN payments p

    WE (e.entity_id = p.entity_id)

    LEFT OUTER JOIN pmt_stat_lookup ps

    WE (p.status_id = ps.status_id

    and ps.forecast = 'Y')

    LEFT OUTER JOIN bri_recon br

    WE (e.entity_id = br.entity_id)

    E.entity group

    My problem with the join where I join p.status_id for ps.status_id and ps.forecast = 'Y '...   If I run the above statement, it seems does not account for this filter criteria and summarizes all records of PAYMENTS, regardless of...  If I move outside the outer join clause, it only brings back the records of PAYMENTS where there is a join. Ive tried to join in a different order etc... but in vain...

    If someone could help, Id be very grateful.

    Kind regards

    Richard

    Hello Richard

    Try this query:

    SELECT e.entity as ENTITY

    sum (PO.amount) as Forecast_Income

    sum (br.bri_credit) as Actual_Income

    sum (br.bri_debit) as Actual_Expenses

    Of

    E ENTITIES

    LEFT OUTER

    JOIN (SELECT P.entity_id )

    P.amount

    PAYMENTS P

    JOIN PMT_STAT_LOOKUP PS

    ON p.status_id = ps.status_id

    AND ps.forecast = 'Y '.

    ) IN.

    WE e.entity_id = in. entity_id

    LEFT OUTER

    JOIN BR BRI_RECON

    ON e.entity_id = br.entity_id

    E.entity GROUP

    ;

    I hope it helps.

    Best regards, David

    Post edited by: David Berger

  • outer join with the additional constraint

    Hello

    With the help of Oracle 11 g R2.

    I would of outer join tables 2 together and put down restrictions on the types of records that are returned in the query result. Here's a mock-up of the tables and data.

    create table aaa (col1 number not null, col2 number not null)

    create table bbb (col1 number not null, col2 number not null)

    insert into values of aaa (1: 80)

    insert into values aaa (2, 90)

    insert into values aaa (3, 80)

    insert into values aaa (4, 90)

    insert into values aaa (5, 80)


    insert into bbb values (3, 600)

    insert into values of bbb (4, 700)

    This is the query

    
    select a.col1, a.col2, b.col1, b.col2
    from aaa a, bbb b
    where a.col1 = b.col1 (+)
    and   (a.col2, b.col2) <> ((90, 700))
    

    The result of the query is as follows.

    col1 col1 col2 col2

    1 80

    3 80 3 600

    5 80

    Where col1 = 4 has been deleted, which is an expected result. However, where col1 = 2 has also been removed, which is not a desired outcome. Your response is appreciated.

    Hello

    Here is a way that works for the given sample data:

    SELECT *.

    AAA a

    LEFT OUTER JOIN bbb b ON a.col1 = b.col1

    WHERE the NVL (a.col2, 0) <> 90

    OR NVL (b.col2, 0) <> 700

    ;

    I don't know if that will satisfy your requirements with other data, since you didn't say what your needs are.

    Whenever you have a WHERE clause is applied after the outer join, all columns of the table in option (table bbb in this example) must be used in an NVL, NVL2 or something like a CASE expression that takes into account null values; otherwise, the effect will be the same as an inner join.

  • outer join on the left, needs improvement

    Two table t1 and t2 where t1.col1 = t2.col2
    create table t1 ( col1 varchar2(20));
    insert into t1 values('aa');
    insert into t1 values('bb');
    insert into t1 values('cc');
    insert into t1 values('dd');
    insert into t1 values('ee');
    
    
    create table t2 ( col2 varchar2(20) , col3 varchar2(20));
    insert into t2 values('aa','q_aa');
    insert into t2 values('bb',' ');
    insert into t2 values('cc','q_cc');
    insert into t2 values('dd',' ');
    
    
    here is my join query:-
    select t1.col1,t2.col2,t2.col3,
    case when t2.col3 is not null then t2.col3
         when t2.col3 is null then t1.col1 end as name1                                   
    from t1 left outer join t2
    on t1.col1 =t2.col2
    real to come result
    COL1 ^ ^ COL2 ^ ^ COL3 ^ ^ NAME1
    AA ^ ^ ^ aa ^ ^ ^ q_aa ^ ^ ^ q_aa
    BB ^ ^ ^ bb
    CC ^ ^ ^ cc ^ ^ ^ q_cc ^ ^ ^ q_cc
    JJ ^ ^ ^ JJ
    ee^^^^^^^^^^^^^^^^ee

    requirement of result
    COL1 ^ ^ COL2 ^ ^ COL3 ^ ^ ^ NAME1
    AA ^ ^ ^ aa ^ ^ ^ q_aa ^ ^ ^ q_aa
    BB ^ ^ ^ bb ^ ^ ^ bb
    CC ^ ^ ^ cc ^ ^ ^ q_cc ^ ^ ^ q_cc
    JJ ^ ^ ^ DD ^ ^ ^ JJ
    ee^^^^^^^^^^^^^^^^^ ee


    and how can copy paste the result of sql * more... box when I copy paste here it automatically omit the space, as above

    The problem is values col3 to the 'bb' and 'dd' lines are not null, because they have a space in them. You can either remove the space and use:

    nvl(t2.col3,t1.col1) as name1
    

    or tim space out:

    nvl(trim(t2.col3),t1.col1) as name1
    
  • 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 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 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

  • He had to know the right outer join using...

    He had to know the right outer join using...

    For example: first query left outer join for the emp table: SELECT EMPNO, ENAME, D.DEPTNO FROM EMP E, Department D WHERE the E.DEPTNO = D.DEPTNO)

    Second query left outer join for the Dept table: SELECT EMPNO, ENAME, D.DEPTNO FROM EMP E, Department D WHERE the D.DEPTNO = E.DEPTNO)

    In the example above I just Exchange where condition condition to get an outer join of two table with a left outer join itself. Wat is use right outer join, instead, I can swap the status of table name for the result. Please suggest...

    Hello

    chan001 wrote:

    He had to know the right outer join using...

    For example: first query left outer join for the emp table: SELECT EMPNO, ENAME, D.DEPTNO FROM EMP E, Department D WHERE the E.DEPTNO = D.DEPTNO)

    Second query left outer join for the Dept table: SELECT EMPNO, ENAME, D.DEPTNO FROM EMP E, Department D WHERE the D.DEPTNO = E.DEPTNO)

    In the example above I just Exchange where condition condition to get an outer join of two table with a left outer join itself. Wat is use right outer join, instead, I can swap the status of table name for the result. Please suggest...

    The two examples above use the old syntax outer join of Oracle. (I guess there should be a sign inside the parentheses, e.g.. +)

    ...  WHERE E.DEPTNO = D.DEPTNO (+)

    )

    The LEFT OUTER JOIN and RIGHT OUTER JOIN terms apply only to the ANSI join syntax, e. g.

    .

    .. FROM EMP E

    DEPT LEFT OUTER JOIN D ON E.DEPTNO = D.DEPTNO

    As Blushadow said above, there's no real point in having LEFT OUTER JOIN and RIGHT OUTER JOIN;  What you can do with one (or a combination of both) can be done with the other.  Most people use LEFT OUTER JOIN systematically and never use RIGHT OUTER JOIN.

    There are situations where using a combination of the two would mean a little less striking, but only a little less and this kind of situation is very common, and one may wonder if the somewhat shorter code is more specific.  I suggest that forget you RIGHT OUTER JOIN.

  • Outer join to find the missing?

    I have 2 tables:

    with stud_courses as
    (
    Select studentid 111, 2, 2201 coursecategory courseid, 'A' GRADE of double
    Union
    Select studentid 111, 2, 2203 coursecategory courseid, CATEGORY "B" of the double
    Union
    Select studentid 111, 4 coursecategory, 2121 courseid, 'A' GRADE of double
    Union
    Select studentid 222, 3 coursecategory, 1111 courseid, 'A' GRADE of double
    Union
    Select studentid 222, 3 coursecategory, 1112 courseid, 'A' GRADE of double
    )
    course_categories as
    (
    Select 2 coursecategory, 2201 courseid double
    Union
    Select 2 coursecategory, 2202 courseid double
    Union
    Select 2 coursecategory, 2203 courseid double
    Union
    Select 2 coursecategory, 2204 courseid double
    Union
    Select 3, 1110 coursecategory courseid double
    Union
    Select 3 coursecategory, 1111 courseid double
    Union
    Select 3 coursecategory, 1112 courseid double
    Union
    Select 3 coursecategory, 1113 courseid double
    Union
    Select 4 coursecategory, 2120 courseid double
    Union
    Select 4 coursecategory, 2121 courseid double
    Union
    Select 4 coursecategory, 2122 courseid double
    Union
    Select 4 coursecategory, 2123 courseid double
    )

    For each student, wants to add the missing courseids for the coursecategory he takes. So student because 111 is in coursecategory 2 I should be able to show all results for him, including the ID of course 2202 and 2204 of category 2 and 2120, 2122, 2123 for this child

    My end result would be something like:

    StudentID, courseid, coursecategory, grade
    111,2,2201, "A".
    111,2,2201, '
    111,2,2203, 'B '.
    111,2,2201, '
    111,4,2120, '
    111,4,2121, "A".
    111,4,2122, '
    111,4,2123, '
    222,3,1110, '
    222,3,1111, "A".
    222,3,1112, "A".
    222,3,1113, '

    I know how to do it with a Union and not exists, but I was wondering if I could do it with an outer join.

    I would appreciate your help.

    Thank you

    Hello

    Yes, you can do it with an outer join. The tricky thing is you need outside to join the table real stud_courses to something that has valid all combinations of the studnents and prices. There is no single table that contains it; the following query will receive these combinations by making a cross join:

    WITH     all_students     AS
    (
         SELECT DISTINCT     studentid
         FROM          stud_courses
    )
    ,     got_category_cnt     AS
    (
         SELECT     all_s.studentid
         ,     c.coursecategory
         ,     c.courseid
         ,     NVL ( s.grade
                  , 'M'
                  )               AS grade
         ,     COUNT (s.grade) OVER ( PARTITION BY  all_s.studentid
                                     ,          c.coursecategory
                             )      AS category_cnt
         FROM           all_students         all_s
         CROSS JOIN      course_categories  c
         LEFT OUTER JOIN      stud_courses         s  ON    s.studentid     = all_s.studentid
                                             AND   s.courseid          = c.courseid
    )
    SELECT       studentid
    ,       coursecategory
    ,       courseid
    ,       grade
    FROM       got_category_cnt
    WHERE       category_cnt     > 0
    ORDER BY  studentid
    ,       coursecategory
    ,       courseid
    ,       grade
    ;
    

    The results I get are:

    `STUDENTID COURSECATEGORY   COURSEID G
    ---------- -------------- ---------- -
           111              2       2201 A
           111              2       2202 M
           111              2       2203 B
           111              2       2204 M
           111              4       2120 M
           111              4       2121 A
           111              4       2122 M
           111              4       2123 M
           222              3       1110 M
           222              3       1111 A
           222              3       1112 A
           222              3       1113 M
    

    These are a little different from what you have posted.

    user9207291 wrote:
    ...
    StudentID, courseid, coursecategory, grade
    111,2,2201, "A".
    111,2,2201, '
    111,2,2203, 'B '.
    111,2,2201, '
    111,4,2120, '
    111,4,2121, "A".
    111,4,2122, '
    111,4,2123, '
    222,3,1110, '
    222,3,1111, "A".
    222,3,1112, "A".
    222,3,1113, '

    Is it because there are errors in what you posted? Do you really want to have three lines of output for the same studentid (111) and courseid (2201)?

    Looks like there should be a slick way to do this with a partitioned outer join.
    A partitioned outer join matches each row of table A with the lines in table B, but, if there is no correspondence between a given A line and a line to a given partition of B, that the rank of A and the B partition is included in the game anyway. Here, we want the two partition tables.

  • You can force BI outer join in w/o logical SQL Anwser in the Advanced tab

    In the repository of BI, we Protocol, region, Site of Protocol, Dimension of the object and a table of facts containing the physical tables Protocol, region, site and subject as a source in MDB.

    The relationship is that a protocol can have 0, n regions, region 0, n sites and a site 0, n subject, with the fact table of the region contains Protocol WID and done Site contains the Protocol and Feds region, subject is contains the Protocol, the region and Site Feds.

    In reporting on the Protocol and the region, BI users would like to have all the protocols appear in the report, without worrying if a protocol contains regions or not. Even as the Protocol-region-Site reports, etc. I can create these reports with SQL logic in the Advanced tab to force BI joins external Protocol, region or Site, etc.. However, users of BI would be difficult to write these SQLs.

    It seems to me that BI server always uses an inner join in the SQLs generated when the user selects the attributes of Protocol, region and Sites, etc. I played with constant implicit approach.

    I know that I can use outer join to define the logic Table Source in the layer of MDB. Would this tangle Protocol, region and site, tables etc. in MDB? What is the best practice to the MDB template when you want compatible outer join?

    Is there a way to force the BI server to generate outer join in the answers?

    Thanks in advance,

    Shi-ning

    Joins using external in the layer MDB is not recommended because it brings in the tables in the query and also impact performance. The right way to handle this scenario is the ETL.

    Add a record to the dimension tables with 0 for the ROW_WID and NULL values for the rest of the columns
    All of fact records without valid WID values for the dimension of research must have a value of 0 instead
    Now when we try to do an INTERNAL JOIN between the fact and any dimension, even those made documents that donot have a valid WID value will also be part of the result. It is essentially an OUTER JOIN operation.

Maybe you are looking for

  • When I send a mass text by enabling / disabling message group, then I turn on message group, suddenly became a group text responses?

    When I send a mass text by enabling / disabling message group, then I turn on message group, suddenly became a group text responses? I sometimes send jokes or notifications to multiple contacts.  After I mass text them by activating / deactivating iM

  • Upgrade SSD on Satellite Pro U200

    Hello! I have a laptop (Satellite Pro U200-PLUA1E-00X007HU of the v3.70 win7 32-bit bios), I want to upgrade with a series of Samsung 830 64 GB SSD. I read that the SSD need AHCI mode. My laptop supports AHCI mode? What can I change in the bios befor

  • Uninstall the pre-installed HP games

    Hello My question is, If I uninstall all games preinstalled on my laptop HP dv7 will it also uninstall Microsoft games too. I want to uninstall the HP games because I don't play them a lot, and those I've played have now is more free time left. I loo

  • Cannot access/locate my user folder after creating a new partition

    I have recently created a new partition on an old hard drive and started own XP but kept all my original data in other partitions. Now after going through the whole upward. I am able to access the data of my other drives connected to my mobo but the

  • The SPACEBAR shortcut does not work.

    The hand appears, but I can't click to pan - it is not catching. If I switch to the hand tool, it does not until I click once, then work. I am running Illustrator CC on 10 of Windows on a new laptop Asus. Thank you in advance for your help!