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

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

  • Combine the two columns of text

    I have two columns of text (say that name is a column and the name is the other)

    I would like to combine the two columns for the text of these two columns are in a column. (First name and last name in the same column)

    Is this possible? If so is there a tutorial somewhere?

    Hi Danielle,

    The & (concatenation operator) is your friend.

    Formula in D2 (fill down)

    "B2 &" "& C2.

    & joins elements into a single string.

    "" inserts a space.

    Kind regards

    Ian.

  • 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

  • Sum of the two columns

    Hello.

    I use jdev 11.1.5

    = > I had created a Vo in the adf with the table named GrlJrl
    I need the sum of the two columns

    My scenario

    Da Ca
    500 100
    600 100
    100 200
    S 400 1200 (adding two field must be displayed in the user interface).

    someone help me reach this goal

    chk this
    Calculate the sum involved new VO

  • calculate the sum of the two columns - display the result in the third column

    Hello

    I have a report and I want to calculate the sum of the two columns of the report and display the total in the third column.

    For example: Sample_My_Report

    Col1 Col2 (Col1 and Col2) Total

    3-7-10


    can someone help me with this question.

    Thank you.

    Hello:

    If your report is an IR you can use the menu "Tool" to add columns calculated at the State

    CITY

  • Do not update the column if the source column is null

    Hi all
    I'm trying to update some columns on the target, I won't update the column if the source is NULL for the column (do not replace the old value if the new value is zero). How can I do this using OWB. I use 11,1 g.

    Any help will be greatly appreciated.

    Thank you
    Ravi

    There are a few ways to do this:

    First of all, you can add your target to the canvas a second time as a source, an outer join to the source of queries on the same fields that you use in your target match constraint, and then run the new value and the existing value in an expression to generate the control you need and send the existing value if the new value is null.

    Alternatively, you can use a splitter on the lines with a single stream going where your field is null in this case update you the target without updating this field and the other the field update stream. This means that the generated code will now be an update of re-encoding re - query the same sources for the second pass, and that any recovery strategy you are not dependent on each mapping succeeding or failing as a total unit will have to be reconsidered.

    Or, of course, you can just put a trigger on the table to check the: new.value and overwrite it with the: if old.value: new.value is null.

    Mike

  • 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

  • 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: difference between two queries

    Below two queries which should give the same results in my opinion. I want that all records of u_protocol and the pval.u_protocol_variable_value value if necessary.

    Why the outer join in query2 does not work as in query1?


    Query1:
    select p.u_protocol_id, i.u_protocol_variable_value
    from lims_sys.u_protocol p,
    (
       select pval.u_protocol_id, pval.u_protocol_variable_value
       from lims_sys.u_protocol_variable pvar, lims_sys.u_protocol_value_user pval
       where pvar.u_protocol_variable_id = pval.u_protocol_variable_id
       and pvar.name = 'VALUE_Protocol_Group'
    ) i   
    where p.u_protocol_id  = i.u_protocol_id (+)
    Query2:
    select prt.u_protocol_id, pval.u_protocol_variable_value
    from lims_sys.u_protocol prt, lims_sys.u_protocol_variable pvar, lims_sys.u_protocol_value_user pval
    where pvar.u_protocol_variable_id = pval.u_protocol_variable_id
    and prt.u_protocol_id = pval.u_protocol_id (+)
    and pvar.name = 'VALUE_Protocol_Group'

    Hello

    When you perform an outer join, all conditions on the tables in option must be outer join conditions. Otherwise, the effect is an inner join.
    There is one exception: cascade of outer joins, external-junction b of a and c is outside attached to b. In this case, in the b - c join only columns of c are marked with the sign +.

    Re - write to obtain the same results as query1, query2 like this:

    select  prt.u_protocol_id
    ,      pval.u_protocol_variable_value
    from     lims_sys.u_protocol          prt
    ,      lims_sys.u_protocol_variable     pvar
    ,      lims_sys.u_protocol_value_user pval
    where     pvar.u_protocol_variable_id (+)     = pval.u_protocol_variable_id     -- cascading outer join
    and     prt.u_protocol_id           = pval.u_protocol_id (+)
    and     pvar.name (+)               = 'VALUE_Protocol_Group'     -- (+) added
    ;
    

    I find the syntax ANSI easier to use for all the joins and much easier for outer joins.

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

  • How to read the two columns of data in a file of PDM.

    Hi all

    I am reading two data columns for the 2nd of a PDM file two sheets, as shown below.

    Two columns of data must then be shared so they can be displayed in a xy chart and also apply a linear adjustment VI. I implemented the graph xy and linear adjustment using a txt file (see below), therefore all the outputs work, however this application with a tdms file turns a little more tax.

    So, essentially, that I don't know how read the correct leaf and therefore the columns in the PDM file and then how to produce the graph xy and linear adjustment of the data types produce. Here's my current attempt, which produces several errors of the type of terminal, as well as not being able to select the exact data in the PDM.

    Any help/suggestions/example vi on this asap would be greatly appreciated.

    Thanks in advance,

    Pete

    Also the PDM file viewer. VI helps you easily understand the structure of data files.

Maybe you are looking for

  • Most of my icons (for example photos of Amazon book) have disappeared. How to make a comeback?

    Recently, most of the icons that indicate specific sources or places or actions on web pages in my browser ceased to appear. I get no picture or only the generic gray icons (such as a document icon). He makes most of the sites (e.g. Amazon) almost un

  • Bluetooth device not detected

    I buy hp g6 2295sx yesterday... Blutooth driver is installed. I want to set up bluetooth headset... but he said bluetooth perepheral drivers not installed... for it, I install some bluetooth software. messages no blutooth device detected... Please he

  • HP Envy 700-470na: changing the case of the HP Envy 700-470na.

    Today, I upgraded my PSU and GPU for my HP Envy 700-470na. The case for my PC is too small and I can barely sort out the cables.If someone can recommend a decent case that is less than £50, can put all the pieces of pc HP in the case like the motherb

  • Photos library download to iCloud: it is stuck or just really slow?

    I am trying to load a very large photo library on iCloud and am trying to determine how far along is progressing or if it is stuck. in Photos, I can go to preferences-online iCloud where he says: "now uploading xx, xxx files...". ».  However, this nu

  • App Store access not updated

    The App Store on my Mac icon says there are 1 update. It is the latest version of iTunes. I can't access the App Store update page (color wheel guard just spinning) and I don't seem able to update iTunes otherwise. Any advice? Thank you