Outer join with a constant

Outer join when made between the columns of the two tables is easy to understand and I'm familiar with it. But when it comes to the same join with a constant, my head starts spinning... you guys can help me with this? I would appreciate that show you with examples.
Thanks a ton.

Hello

>
Ok... I want to understand the output of the last sql statement given here.
...
Select * from a, b
where col_a (+) = col_b
and col_a (+) = 1

It shows put it is as follows
col_a, col_b
1 1
2 NULL
NULL NULL

Joining means: 'display all rows in table b and the corresponding rows in the table one '.
Since it is an outer join, it also means "view b lines even if there is no corresponding row in a.

Thus, the output contains 3 lines, which correspond to the 3 lines in b.
Only one of them (the one with col_b = 1) had a game in a.col_a, if the column is NULL in the other lines.

With the sample data you posted, you will get the same results without condition

and     col_a (+) = 1

If you want to understand what makes this condition, use some examples of data where this condition would fail.
For example, add this line to the table a:

insert into a values (2);

and run your original query (including the)

and     col_a (+) = 1

). what output you get? You get the same exact results you did without the new line in a.

In other words, the b line where col_b = 2 has still no matches in the table has.
True, there is now a line of table where col_a = 2, but which does not constitute a game. A match is defined by two conditions:

where   col_a (+) = col_b
and     col_a (+) = 1

in order to have a pair of lines which meets only the first condition

where   col_a (+) = col_b

is not enough.

Tags: Database

Similar Questions

  • Left Outer Join with sum

    Dear elders,



    Firstly, sorry if my question is considered to be 'very novice' but I have this problem of confusion.

    Can I use the left outer join with summary?
    For example:

    Work table
    JobCode      JobGroupCode      
    111A         1100              
    112B         1100               
    113C         1100
    121A         1200
    333F         3300               
    Table No.
    JobGroupCode    ParentCode
    1100            1000
    1200            1000
    1300            1000
    3300            3000
    Activity table
    Jobcode      Mandays
    111A         5
    112B         7
    113C         3
    I want to choose with this result
    Job.JobCode    Job.JobGroupCode     JobGroup.Parentcode       Mandays
    111A           1100                 1000                      5
    112B           1100                 1000                      7               
    113C           1100                 1000                      3
    121A           1200                 1000                      0
    333F           3300                 3000                      0
    All I did was:
    select j.jobcode, j.jobgroupcode, jg.parentcode, sum(a.mandays)
      from job j
     inner join jobgroup jg on j.jobgroupcode = jg.jobgroupcode
      left join activity a on j.jobcode = a.jobcode
     group by j.jobcode, j.jobgroupcode, jg.parentcode
    and I got was only jobcode activity table, not exactly what I want to get all the work table jobcode. Could you please tell me, where I was wrong?

    result
    Job.JobCode    Job.JobGroupCode     JobGroup.Parentcode       Mandays
    111A           1100                 1000                      5
    112B           1100                 1000                      7               
    113C           1100                 1000                      3
    Thank you very much.

    Published by: user11197113 on May 25, 2009 03:31

    Published by: user11197113 on May 25, 2009 03:32

    Hello (and welcome!).

    Edit

    OK, try this:

    select j.jobcode, j.jobgroupcode, jg.parentcode, NVL(sum(a.mandays),0)
      from job j
     inner join jobgroup jg on j.jobgroupcode = jg.jobgroupcode
      left join activity a on j.jobcode = a.jobcode
     group by j.jobcode, j.jobgroupcode, jg.parentcode
    

    That will give you this:

    JOBC JOBG PARE SUM(A.MANDAYS)
    ---- ---- ---- --------------
    111A 1100 1000              5
    112B 1100 1000              7
    113C 1100 1000              3
    121A 1200 1000              0
    333F 3300 3000              0
    

    These are real results of your test data.

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

  • HELP SQL (auto / full outer join with date corresponding)

    I'm having a hard time get this query nailed... hoping someone can help me sorted.

    create table tab1 (identification number,

    date of eff_date,

    Code1 varchar2 (2),

    Code2 varchar2 (2)

    )

    /

    insert into tab1 values (2, to_date('2015-01-14','YYYY-MM-DD'), 'DAT', 'AS');

    insert into tab1 values (2, to_date('2015-03-19','YYYY-MM-DD'), 'DAT', 'AS');

    insert into tab1 values (2, to_date('2015-08-28','YYYY-MM-DD'), 'DAT', 'AS');

    insert into tab1 values (2, to_date('2015-11-12','YYYY-MM-DD'), 'DAT', 'AS');

    insert into tab1 values (2, to_date('2015-01-03','YYYY-MM-DD'), "DAT", "AE");

    insert into tab1 values (2, to_date('2015-03-14','YYYY-MM-DD'), "DAT", "AE");

    insert into tab1 values (2, to_date('2015-04-18','YYYY-MM-DD'), "DAT", "AE");

    insert into tab1 values (2, to_date('2015-09-14','YYYY-MM-DD'), "DAT", "AE");

    insert into tab1 values (2, to_date('2015-01-14','YYYY-MM-DD'), "DAT", "BS");

    insert into tab1 values (2, to_date('2015-02-14','YYYY-MM-DD'), "DAT", "BS");

    insert into tab1 values (2, to_date('2015-03-14','YYYY-MM-DD'), "DAT", "BS");

    insert into tab1 values (2, to_date('2015-05-14','YYYY-MM-DD'), 'DAT', 'BE');

    insert into tab1 values (3, to_date('2015-09-16','YYYY-MM-DD'), 'DAT', 'AS');

    insert into tab1 values (3, to_date('2015-04-16','YYYY-MM-DD'), "DAT", "AE");

    tab1

    ID, date, code 1, code2

    2. DID DAT 2015-01-14

    2. DID DAT 2015-03-19

    2. DID DAT 2015-08-28

    2. DID DAT 2015-11-12

    2 AE DAT 2015-01-03

    2 AE DAT 2015-03-14

    2 AE DAT 2015-04-18

    2 AE DAT 2015-09-14

    2 BS DAT 2015-01-14

    2 BS DAT 2015-02-14

    2 BS DAT 2015-03-14

    BE DAT 2 2015-05-14

    3. DID DAT 2015-09-16

    3 AE DAT 2015-04-16

    What I need to do...

    1 auto join to match EI for each partition ID

    2. THAT the date must be less than or equal to the date of the AE and when there is more then a line corresponding to this criterion has chosen the date of closest EI of the date of the ACE.

    3. it must be a full outer join because I want to show all lines, even if it is not a match.  There is a beginning, but not record end end gold but no record of departure

    4. If there is an AE line for many AS lines (the SA date is less then equals the date of EI) then join this AE line to all 3 rows of ACE

    5. the same rules for BS and BE.

    result should look like this.

    ID, date, code 1, id_1 code2, date_1, code1_1, code2_1

    2 2015-01-14 DAT AS 2 AE DAT 2015-03-14

    2 2015-03-19 DAT AS 2 AE DAT 2015-04-18

    2 2015-08-28 DAT AS 2 AE DAT 2015-09-14

    2 2015-11-12 DAT DID ZERO ZERO ZERO ZERO

    NO NO NO NO 2 AE DAT 2015-01-03

    2015-01-2 14 DAT BS 2 BE DAT 2015-05-14

    2015-02-2 14 DAT BS 2 BE DAT 2015-05-14

    2015 03-2 14 DAT BS 2 BE DAT 2015-05-14

    3 2015-09-16 DAT DID ZERO ZERO ZERO ZERO

    NO NO NO NO 3 AE DAT 2015-04-16

    My attempt was somewhat along these lines (dealing only with SA / combos AE) but it does not manage the many scenarios one (req 4).

    Select a.*, b.* from

    (select row_number () on the rn (partition by a.id order a.eff_date), a.*)

    of tab1 where a.code2 = 'AS') a

    full outer join

    (select row_number () on the rn (b.eff_date order by b.id partition), b.*)

    tab1 b where b.code2 = 'Æ') b

    on a.id = b.id

    and a.rn = b.rn

    and a.eff_date < = b.eff_date

    Hello

    owbdev99 wrote:

    I'm having a hard time get this query nailed... hoping someone can help me sorted.

    create table tab1 (identification number,

    date of eff_date,

    Code1 varchar2 (2),

    Code2 varchar2 (2)

    )

    /

    insert into tab1 values (2, to_date('2015-01-14','YYYY-MM-DD'), 'DAT', 'AS');

    ...

    Thanks for posting the CREATE TABLE and INSERT.  I know it can be a lot of trouble.  You want to get answers that work, not you?  Make sure that the statements you post too much work.  Test (and, if necessary, attach) your statements before committing.  You said code1 be VARCHAR2, but all the instructions insertion have values of 3 characters for code1.

    You are on the right track, with an analytical function, but ROW_NUMBER solves this problem.  1 "THAT line" could correspond to the 1st, 2nd, 3rd or any other line 'AE' and vice versa.  Try to use the analytical MIN function instead or ROW_NUMBER, like this:

    WITH got_next_e_date AS

    (

    SELECT id, eff_date, code1, code2

    MIN (CASE

    WHEN SUBSTR (code2, 2) = 'E '.

    THEN eff_date

    END

    ) OVER (PARTITION BY ID.

    , SUBSTR (code2, 1, 1)

    ORDER BY eff_date DESC

    ) AS next_e_date

    OF tab1

    )

    s AS

    (

    SELECT *.

    OF got_next_e_date

    "WHERE SUBSTR (code2, 2) s ="

    )

    e

    (

    SELECT *.

    OF got_next_e_date

    WHERE SUBSTR (code2, 2) = 'E '.

    )

    SELECT s.id

    s.eff_date

    s.code1

    s.code2

    e.id AS id_1

    e.eff_date AS eff_date_1

    e.code1 AS code1_1

    e.code2 AS code2_1

    S

    FULL OUTER JOIN e ON s.id = e.id

    AND s.next_e_date = e.eff_date

    AND SUBSTR (s.code2, 1, 1) = SUBSTR (e.code2, 1, 1)

    ORDER OF NVL (s.id, e.id)

    , NVL (SUBSTR (s.code2, 1, 1)

    , SUBSTR (e.code2, 1, 1)

    )

    s.eff_date

    ;

    Out (as you asked):

    ID EFF_DATE CODE1, CODE2 ID_1 EFF_DATE_1 CODE1_1 CODE2_1

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

    2 2015-01-14 DAT AS 2 AE DAT 2015-03-14

    2 2015-03-19 DAT AS 2 AE DAT 2015-04-18

    2 2015-08-28 DAT AS 2 AE DAT 2015-09-14

    2. DID DAT 2015-11-12

    2 AE DAT 2015-01-03

    2015-01-2 14 DAT BS 2 BE DAT 2015-05-14

    2015-02-2 14 DAT BS 2 BE DAT 2015-05-14

    2015 03-2 14 DAT BS 2 BE DAT 2015-05-14

    3. DID DAT 2015-09-16

    3 AE DAT 2015-04-16

    I guess code2 is always 2 characters, and the 2nd character is always ' or 'E '.

    I assume that the combination [id, eff_date, code2] is unique.

    If these assumptions are wrong, you need a few minor changes, but nothing big.

  • Why left outer join with a table gives me more lines?

    Hi gurus,

    I can see "view_a" and a table 'table_a '.

    view_a a county of 100 lines. Now, when I left outer join that discovers with a 'table_a', I expect all 100 lines.

    However, I'm more than 100 lines. Is it still possible?

    Also even to analyze these situations, how can I move forward?

    Because it is very high volumn of sight and takes longer to run.

    Select count (*) view_a, view_b

    where view_a.col1 = view_b.col1 (+)

    and view_a.col2 = view_b.col2 (+);

    Thank you

    I can see "view_a" and a table 'table_a '.

    view_a a county of 100 lines. Now, when I left outer join that discovers with a 'table_a', I expect all 100 lines.

    However, I'm more than 100 lines. Is it still possible?

    Also even to analyze these situations, how can I move forward?

    Because it is very high volumn of sight and takes longer to run.

    Select count (*) view_a, view_b

    where view_a.col1 = view_b.col1 (+)

    and view_a.col2 = view_b.col2 (+);

    Which is not necessarily related to the use of an outer join.

    Just join of two tables in general will give you more rows of one table has.

    Scott DEPT table contains ONE row for deptno = 10

    The EMP table has THREE rows of deptno = 10

    The number of rows you plan if you join two tables using an equi-join?

    Three - what is MORE lines the DEPT table has for deptno = 10

    Select * from Department where deptno = 10

    DEPTNO, DNAME, LOC
    10, ACCOUNTING, NEW YORK

    Select * from emp where deptno = 10

    MGR, EMPLOYMENT ENAME, EMPNO, HIREDATE, SAL, COMM, DEPTNO
    7782, CLARK, MANAGER, 7839, 6/9/1981,2450, 10
    7839, KING, PRESIDENT, 17 NOVEMBER 00, 10
    7934, MILLER, CLERK, 7782, 23 JANUARY 00: 10

    Select dept.*, emp.*
    Department, emp
    where dept.deptno = 10
    and dept.deptno = emp.deptno

    DEPTNO, DNAME, LOC, EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO_1
    10, ACCOUNTING, NEW YORK, 7782, CLARK, MANAGER, 7839, 6/9/1981,2450, 10
    10, ACCOUNTING, NEW YORK, 7839, KING, PRESIDENT, 17 NOVEMBER 00, 10
    10, ACCOUNTING, NEW YORK, 7934, MILLER, CLERK, 7782, 23 JANUARY 00: 10

    So if these are the lines ONLY in the table EMP and DEPT the query would give you THREE lines despite the DEPT table only ONE line.

    No do you expect? You get ALL the child rows that belong to the parent company. Otherwise, how could it possibly work?

    The OUTER join includes lines where the parent row exists but there is NO child line as others have shown.

    Outer joins

    Outer join extends the result of a simple join. Outer join returns all rows that satisfy the join condition and also returns some or all rows in a table for which no line of the other meet the join condition.

    Get more lines to exist in one of the paintings is a basic necessity. It usually has NOTHING to with the question of whether you have an outside to join or not.

    See the section on the JOINTS in the Oracle documentation

    http://docs.Oracle.com/CD/B28359_01/server.111/b28286/queries006.htm

  • Former Outer Join syntax on constants

    Hello

    Can someone please tell me why the below two queries are performing differently. How to join a constant by using the old syntax used.

    Also, how is 3 different query of query 2?

    CREATE TABLE T1 (X VARCHAR2 (10), B INTEGER);

    CREATE TABLE T2 (Y VARCHAR2 (10), B INTEGER);

    INSERT INTO T1 VALUES('XXX',10);
    INSERT INTO T1 VALUES('XXX',10);
    INSERT INTO T1 VALUES('XXX',10);
    INSERT INTO T1 VALUES('YYY',20);
    INSERT INTO T1 VALUES('YYY',20);
    INSERT INTO T1 VALUES('YYY',20);

    INSERT INTO T2 VALUES('AAA',10);
    INSERT INTO T2 VALUES('BBB',20);

    Query 1

    SELECT T1.*, T2.* FROM T1 LEFT JOIN T2

    ON T1. B = T2. B

    AND T1. B = 20

    -OUTPUT

    =========

    BBB YYY 20 20

    BBB YYY 20 20

    BBB YYY 20 20

    NULL NULL 10 XXX

    NULL NULL 10 XXX

    NULL NULL 10 XXX

    Query 2

    SELECT T1.*, T2.* FROM T1, T2

    ON T1. B (+) = T2. B

    AND T1. B ( + ) = 20;

    OUTPUT

    =======

    BBB YYY 20 20

    BBB YYY 20 20

    BBB YYY 20 20

    Request 3

    SELECT T1.*, T2.* FROM T1, T2

    ON T1. B (+) = T2. B

    ET T2. B ( + ) = 20;

    -OUTPUT

    =========

    BBB YYY 20 20

    BBB YYY 20 20

    BBB YYY 20 20

    NULL NULL 10 XXX

    NULL NULL 10 XXX

    NULL NULL 10 XXX

    Thank you and best regards,

    Mathieu

    Hi, nada.

    967250 wrote:

    Hello

    My apologies for errors in queries.

    Please find the three queries

    QUERY1

    SELECT T1.*, T2.*
    T1 LEFT JOIN T2
    ON T1. B = T2. B
    AND T1. B = 20;

    QUERY2

    SELECT T1.*, T2.*
    FROM T1, T2
    WHERE T1. B = T2. B ( + )
    AND T1. B (+) = 20;

    QUERY3
    SELECT T1.*, T2.*
    FROM T1, T2
    WHERE T1. B = T2. B ( + )
    AND T2. B (+) = 20;

    Query 1 and 3 produce the same results. I want to know is what is the difference between Q2 and (T1 or T3)

    Thank you

    Mathieu

    In the query above 1, t1 is the required table (LEFT OUTER JOIN means the table on the LEFT is needed, and the other table is optional).

    Query 3 is the way to do the same in the old notation.

    If you use the old notation of outer join, the + sign is used by reference to the table as an option.  It should always apply for t1 or t2, not sometimes one and sometimes the other, which is what you do in the application 2.  In the State:

    T1. B = T2. B ( + )

    you say that t2 is optional; in the other condition

    T1. B (+) = 20

    you say that t1 is optional.  I don't know why that does not raise an error.  Apparently, it is just to ignore the sign in this last condition.

  • 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 with Oracle syntax

    Hi, I am new to oracle and I worked this request for reports for about 2 weeks, please take a look at my request
    SELECT mmt.transaction_date "Transaction Date", 
                msib.segment1 "Item", 
                gcc.segment1||'-'||gcc.segment2||'-'||gcc.segment3||'-'||gcc.segment4||'-'||gcc.segment5||'-'||gcc.segment6||'-'||(nvl(gcc.segment7,'000000')) "account",
                (CASE mttype.transaction_type_name
                WHEN 'Average cost update' THEN
              ((nvl(mmt.new_cost,0) - nvl(mmt.prior_cost,0)) * nvl(mmt.quantity_adjusted,0)) + nvl(mmt.variance_amount,0)
                ELSE
                 (mmt.Primary_quantity * nvl(mmt.actual_cost, 0) + nvl(mmt.variance_amount, 0))
               END) "Transaction Value",
                mttype.description "Transaction Type",
                mmt.subinventory_code "Subinventory",
                ood.organization_code "Org",
                msib.Primary_UOM_Code "UOM",
                mmt.Primary_Quantity "Primary Quantity",
                mtr.description "Reason",
                mmt.transaction_reference "Reference"
    FROM mtl_material_transactions mmt,
             mtl_system_items_b msib,
             mtl_transaction_accounts mta,
             gl_code_combinations gcc,
             mtl_transaction_types mttype,
             Org_Organization_Definitions ood,
             mtl_transaction_reasons mtr
    WHERE mmt.transaction_date >= :P_DATE_FROM 
               and mmt.transaction_date  < :P_DATE_TO +1
               and mmt.organization_id = :P_ORGANIZATION 
               and msib.organization_ID = mmt.organization_ID  
               and msib.inventory_item_id=mmt.inventory_item_id 
               and mta.transaction_id=mmt.transaction_id
               and gcc.code_combination_id = mta.reference_account
               and mttype.transaction_type_id=mmt.transaction_type_id
               and mmt.reason_id=mtr.reason_id(+)
               and ood.organization_id=mmt.organization_id
               and mttype.transaction_type_id = :P_TRANSACTION_TYPE
               and msib.segment1 = :P_ITEM
               AND gcc.segment2 = :P_ACCOUNT
    null values is on the mtl_material_transactions table, which is reason_id, subinventory_code and transaction_reference
    put desired option on would show all archives on mtl_material_transactions with null values
    so I put the symbol of the outer join right?
    BTW
    I tried to put the (+) sign on various locations but it still not good and I am really at a loss

    Hello

    Whenever you have any questions, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) and the desired results from these data. I know that's not always easy, but it is really necessary. Compounds that, I do not understand your problem.
    It could be useful that simplify you the problem. If you were not interested in, say, the mta, gcc, tables msib and ood, would you still have the same problem? If so, forget all these tables and just after, CREATE TABLE and INSERT statements for the remaining tables and the results you want from this data.
    Explain, using specific examples, how you get these results from these data.
    Always tell what version of Oracle you are using.

    The query you posted will not exclude any line of mmt just because it doesn't have a corresponding line in the mtr; That's what the condition:

    and mmt.reason_id=mtr.reason_id(+)
    

    but it will exclude mmt lines if they do not have matching rows in other tables. Maybe you need + plus join and may under certain conditions non-join, such as conditions

    gcc.segment2 (+) = :P_ACCOUNT
    

    Too much. It's just a guess. Without seeing your sample data and the correct results, you should get from this data, I can't say.

  • Using Left Outer Join with reference

    I have three tables.
    Table 1: BOOK_DETAILS
    Fields: BOOK_ID, BOOK_NAME

    Table 2: BOOK_ISSUE_RECORD
    Fields: BOOK_ID, USER_NAME

    Table 3: BOOK_AUTHOR
    Fields: BOOK_ID, AUTHOR_NAME

    I must link table 1 and table 2 with a left outer join, because even if the book is not the questions to anyone, his name should come.
    I have once again display the name of the author of books for each book.
    I am able to create a query with the left outer join between table 1 and table 2. However, I am not able to give a reference to Table 3.
    Can someone help me with this please.

    Concerning
    Hawker
    select  d.book_name,
            a.book_author,
            i.user_name
      from       book_details d
            join
                 book_author a
              on (d.book_id = a.book_id)
            left join
                 book_issue_recors i
              on (d.book_id = i.book_id)
    /
    

    SY.

  • outer join with syntax plus sign

    To do this in Sql outer joins can be used as grammar:
    ( + )
    What are the standards (ISO, ANSI and what version) created this grammar?
    Or is it only the invention of Oracle?

    Published by: CharlesRoos on July 1st, 2010 07:23

    Apparently, he was "there are chandeliers" ;)

    http://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:2419891400346921578 #2439016200346544570

  • Outer join with lpad

    Hello

    We have this basic question that works very well:
    Select pp.upc, a.barcode from the ALBUM, PHYSICALPRODUCT RP where lpad (pp.upc, 13, '0') = lpad (a.barcode, 13, '0')

    But we wanted to do an outer join. If we remove the lpad, it works. But if we as below, we have ORA-00936, lack of expression:

    Select pp.upc, a.barcode from the ALBUM, PHYSICALPRODUCT RP where lpad (pp.upc, 13, '0') (+) = lpad (a.barcode, 13, '0')

    If anyone can help us in this regard.

    Thks.

    Outer join can be used outside the functions of text
    It will be like

    select pp.upc, a.barcode from ALBUM a, PHYSICALPRODUCT pp where lpad(pp.upc (+), 13, '0')  = lpad(a.barcode, 13, '0')
    
  • BAD RESULTS WITH OUTER JOINS AND TABLES WITH A CHECK CONSTRAINT

    HII All,
    Could any such a me when we encounter this bug? Please help me with a simple example so that I can search for them in my PB.


    Bug:-8447623

    Bug / / Desc: BAD RESULTS WITH OUTER JOINS AND TABLES WITH a CHECK CONSTRAINT


    I ran the outer joins with check queries constraint 11G 11.1.0.7.0 and 10 g 2, but the result is the same. Need to know the scenario where I will face this bug of your experts and people who have already experienced this bug.


    Version: -.
    SQL> select * from v$version;
    
    BANNER
    --------------------------------------------------------------------------------
    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
    PL/SQL Release 11.1.0.7.0 - Production
    CORE    11.1.0.7.0      Production
    TNS for Solaris: Version 11.1.0.7.0 - Production
    NLSRTL Version 11.1.0.7.0 - Production

    Why do you not use the description of the bug test case in Metalink (we obviously can't post it here because it would violate the copyright of Metalink)? Your test case is not a candidate for the elimination of the join, so he did not have the bug.

    Have you really read the description of the bug in Metalink rather than just looking at the title of the bug? The bug itself is quite clear that a query plan that involves the elimination of the join is a necessary condition. The title of bug nothing will never tell the whole story.

    If you try to work through a few tens of thousands of bugs in 11.1.0.7, of which many are not published, trying to determine whether your application would be affected by the bug? Wouldn't be order of magnitude easier to upgrade the application to 11.1.0.7 in a test environment and test the application to see what, if anything, breaks? Understand that the vast majority of the problems that people experience during an upgrade are not the result of bugs - they are the result of changes in behaviour documented as changes in query plans. And among those who encounter bugs, a relatively large fraction of the new variety. Even if you have completed the Herculean task of verifying each bug on your code base, which would not significantly easier upgrade. In addition, at the time wherever you actually performed this analysis, Oracle reportedly released 3 or 4 new versions.

    And at this stage would be unwise to consider an upgrade to 11.2?

    Justin

  • [8i] need help with full outer join combined with a cross join...

    I can't understand how to combine a full outer join with a different type of join... is it possible?

    Here are some create table and insert for examples of database:
    CREATE TABLE     my_tab1
    (     record_id     NUMBER     NOT NULL     
    ,     workstation     VARCHAR2(4)
    ,     my_value     NUMBER
         CONSTRAINT my_tab1_pk PRIMARY KEY (record_id)
    );
    
    INSERT INTO     my_tab1
    VALUES(1,'ABCD',10);
    INSERT INTO     my_tab1
    VALUES(2,'ABCD',15);
    INSERT INTO     my_tab1
    VALUES(3,'ABCD',5);
    INSERT INTO     my_tab1
    VALUES(4,'A123',5);
    INSERT INTO     my_tab1
    VALUES(5,'A123',10);
    INSERT INTO     my_tab1
    VALUES(6,'A123',20);
    INSERT INTO     my_tab1
    VALUES(7,'????',5);
    
    
    CREATE TABLE     my_tab2
    (     workstation     VARCHAR2(4)
    ,     wkstn_name     VARCHAR2(20)
         CONSTRAINT my_tab2_pk PRIMARY KEY (workstation)
    );
    
    INSERT INTO     my_tab2
    VALUES('ABCD','WKSTN 1');
    INSERT INTO     my_tab2
    VALUES('A123','WKSTN 2');
    INSERT INTO     my_tab2
    VALUES('B456','WKSTN 3');
    
    CREATE TABLE     my_tab3
    (     my_nbr1     NUMBER
    ,     my_nbr2     NUMBER
    );
    
    INSERT INTO     my_tab3
    VALUES(1,2);
    INSERT INTO     my_tab3
    VALUES(2,3);
    INSERT INTO     my_tab3
    VALUES(3,4);
    And, the results that I want to get:
    workstation     sum(my_value)     wkstn_name     my_nbr1     my_nbr2
    ---------------------------------------------------------------
    ABCD          30          WKSTN 1          1     2
    ABCD          30          WKSTN 1          2     3
    ABCD          30          WKSTN 1          3     4
    A123          35          WKSTN 2          1     2
    A123          35          WKSTN 2          2     3
    A123          35          WKSTN 2          3     4
    B456          0          WKSTN 3          1     2
    B456          0          WKSTN 3          2     3
    B456          0          WKSTN 3          3     4
    ????          5          NULL          1     2
    ????          5          NULL          2     3
    ????          5          NULL          3     4
    I tried a number of different things, google my problem and no luck yet...
    SELECT     t1.workstation
    ,     SUM(t1.my_value)
    ,     t2.wkstn_name
    ,     t3.my_nbr1
    ,     t3.my_nbr2
    FROM     my_tab1 t1
    ,     my_tab2 t2
    ,     my_tab3 t3
    ...
    So, what I want, it's a full outer join of t1 and t2 on workstation and a cross join of one with the t3. I wonder if I can't find examples of it online because it is not possible...

    Note: I'm stuck dealing with Oracle 8i

    Thank you!!

    Hello

    The query I posted yesterday is a little more complex that it should be.
    My_tab2.workstation is unique, there is no reason to make a separate subquery as mt1. We can join my_tab1 to my_tab2 and get the SUM in a subquery.

    SELECT       foj.workstation
    ,       foj.sum_my_value
    ,       foj.wkstn_name
    ,       mt3.my_nbr1
    ,       mt3.my_nbr2
    FROM       (     -- Begin in-line view foj for full outer join
              SELECT        mt1.workstation
              ,        SUM (mt1.my_value)     AS sum_my_value
              ,        mt2.wkstn_name
              FROM        my_tab1   mt1
              ,        my_tab2   mt2
              WHERE        mt1.workstation     = mt2.workstation (+)
              GROUP BY   mt1.workstation
              ,        mt2.wkstn_name
                            --
                    UNION ALL
                            --
              SELECT      workstation
              ,      0      AS sum_my_value
              ,      wkstn_name
              FROM      my_tab2
              WHERE      workstation     NOT IN (     -- Begin NOT IN sub-query
                                               SELECT      workstation
                                       FROM      my_tab1
                                       WHERE      workstation     IS NOT NULL
                                     )     -- End NOT IN sub-query
           ) foj     -- End in-line view foj for full outer join
    ,       my_tab3  mt3
    ORDER BY  foj.wkstn_name
    ,       foj.workstation
    ,       mt3.my_nbr1
    ,       mt3.my_nbr2
    ;
    

    Thanks for posting the CREATE TABLE and INSERT statements, and very clear expected results!

    user11033437 wrote:
    ... So, what I want, it's a full outer join of t1 and t2 on workstation and a cross join of one with the t3.

    She, exactly!
    The trickiest part is when and how get SUM (my_value). You could address the question of exactly what my_tab3 must be attached to a cross that's exactly what should look like the result set of the full outer join between my_tab1 and my_tab2 to. To do this, take your desired results, remove columns that do not come from the outer join complete and delete duplicate rows. You will get:

    workstation     sum(my_value)     wkstn_name
    -----------     -------------   ----------
    ABCD          30          WKSTN 1
    A123          35          WKSTN 2
    B456          0          WKSTN 3
    ????          5          NULL          
    

    So the heart of the problem is how to get these results of my_tab1 and my_tab2, which is done in the subquery FOJ above.

    I tried to use auto-documenté in my code names. I hope you can understand.
    I could spend hours explaining the different parts of this query more in detail, but I don't know that I would lose some of that time, explain things that you already understand. If you want an explanation of the specific element (s), let me know.

  • Problem format (LEFT OUTER JOIN)?

    THE addresses of Mutiple of return as a single record + current addresses

    >
    Hi all

    I have to back student addresses home and dormitory under a single registration.

    He had to go something like this:
    LAST_NAME     FIRST_NAME     ADDY_TYPE   ADDRESS             ZIP
    Smith                John             HOME         123 Awesome St     10003
    Smith               John               DORM         Oak Quad             10013
    In this format the desired:
    LAST_NAME  FIRST_NAME     ADDY_TYPE  ADDRESS         ZIP        ADDY_TYPE     ADDRESS     ZIP
    Smith            John      HOME        123 Awesome St  10003   DORM            Oak Quad     10013
    You also need to get their last addresses by date.
    The database hold records of all students have places moving from dorm to dorm
    and some permanent residence ("HOME") has changed as well.
    To return only a DORM address and only a HOME address
    for each student.

    I'm looking at possibly a function BOX to put on a line/record and RANK BY() or DENSE_RANK to determine the last addresses.

    Hope I'm making some sense and as always very grateful for any help. Thank you.
    >

    The correct code provided by Frank Kulash here:
    WITH    got_rnum     AS
    (
         SELECT     last_name
         ,     first_name
         ,     addy_type
         ,     address
         ,     zip
         ,     ROW_NUMBER () OVER ( PARTITION BY  last_name
                                   ,                    first_name
                             ,             addy_type
                             ORDER BY        addy_date     DESC     NULLS LAST
                           ) AS rnum
         FROM    table_x
    --     WHERE     ...          -- Any filtering goes here
    )
    SELECT    last_name
    ,       first_name
    ,       MIN (CASE WHEN addy_type = 'HOME' THEN address END)     AS home_address
    ,       MIN (CASE WHEN addy_type = 'HOME' THEN zip     END)     AS home_zip
    ,       MIN (CASE WHEN addy_type = 'DORM' THEN address END)     AS dorm_address
    ,       MIN (CASE WHEN addy_type = 'DORM' THEN zip     END)     AS dorm_zip
    FROM       got_rnum
    WHERE       rnum     = 1
    GROUP BY  last_name
    ,            first_name
    ;
    I need to add a 'NATION' field, located on another table for the addresses of welcome for foreign students.
    I made a LEFT OUTER JOIN with the table of the NATION and the release came out like this:
    LAST_NAME  FIRST_NAME     ADDY_TYPE  ADDRESS   ZIP      NATION    ADDY_TYPE       ADDRESS     ZIP
    Smith            John      HOME        Rue Henry M1V 4F4  CANADA      null              null             null
    Smith            John      null        null      null     null        DORM               Oak Quad     10013
    My desired output would be like this:
    LAST_NAME  FIRST_NAME     ADDY_TYPE  ADDRESS   ZIP      NATION    ADDY_TYPE       ADDRESS     ZIP
    Smith            John      HOME        Rue Henry M1V 4F4  CANADA    DORM              Oak Quad     10013
    Maybe it's something I'm not right. What is the way I'm joining tables?

    As always very grateful for your contributions. Thank you.

    Give a glance to your group by, you group on the nation, but it has two values (NULL and CANADA). Try this way:

    WITH    got_rnum     AS
    (
         SELECT     STUINFO_id
      , STUINFO_last_name
         ,     STUINFO_first_name
         ,     ADDRESSLIST_atyp_code
         ,     ADDRESSLIST_street_line1
      , ADDRESSLIST_street_line2
      , ADDRESSLIST_city
      , ADDRESSLIST_stat_code
         ,     ADDRESSLIST_zip
    
    , ADDRESSLIST_natn_code
    , NATION_nation
         ,     ROW_NUMBER () OVER ( PARTITION BY  STUINFO_last_name
                                   ,                    STUINFO_first_name
                             ,                         ADDRESSLIST_atyp_code
    
                             ORDER BY        ADDRESSLIST_from_date     DESC     NULLS LAST
                           ) AS rnum
         FROM STUINFO JOIN CLASSROSTER ON STUINFO_pidm = CLASSROSTER_pidm JOIN ADDRESSLIST ON ADDRESSLIST_pidm = STUINFO_pidm LEFT OUTER JOIN NATION ON ADDRESSLIST_NATN_CODE =NATION_CODE
    -- The WHERE part determines if the student is currently enrolled in a class
    -- ADDRESSLIST_to_date is the last date the student will be living in that residence
    WHERE ADDRESSLIST_atyp_code IN ('PR', 'CA') and  STUINFO_change_ind IS NULL and STUINFO_last_name !='Registrar'
    and CLASSROSTER_term_code='200909' and CLASSROSTER_PTRM_CODE IN ('D', 'D1', 'D2') and CLASSROSTER_CAMP_CODE='1'
    
    and (ADDRESSLIST_to_date is NULL OR ADDRESSLIST_TO_DATE > SYSDATE)
    )
    SELECT    STUINFO_id
    ,   STUINFO_last_name
    ,       STUINFO_first_name
    ,       MIN (CASE WHEN ADDRESSLIST_atyp_code = 'PR' THEN ADDRESSLIST_STREET_LINE1  END)     AS PR_ADDRESSLIST_STREET_LINE1
    ,       MIN (CASE WHEN ADDRESSLIST_atyp_code = 'PR' THEN ADDRESSLIST_STREET_LINE2  END)     AS PR_ADDRESSLIST_STREET_LINE2
    ,       MIN (CASE WHEN ADDRESSLIST_atyp_code = 'PR' THEN ADDRESSLIST_city     END)     AS PR_ADDRESSLIST_city
    ,       MIN (CASE WHEN ADDRESSLIST_atyp_code = 'PR' THEN ADDRESSLIST_stat_code     END)     AS PR_ADDRESSLIST_stat_code
    ,       MIN (CASE WHEN ADDRESSLIST_atyp_code = 'PR' THEN ADDRESSLIST_zip     END)     AS PR_ADDRESSLIST_zip
    ,       MIN (CASE WHEN ADDRESSLIST_natn_code IS  NULL THEN ADDRESSLIST_natn_code     END)     AS PR_ADDRESSLIST_natn_code
    , MIN(NATION_nation) NATION_nation
    ,       MIN (CASE WHEN ADDRESSLIST_atyp_code = 'CA' THEN ADDRESSLIST_STREET_LINE1  END)     AS CA_ADDRESSLIST_STREET_LINE1
    ,       MIN (CASE WHEN ADDRESSLIST_atyp_code = 'CA' THEN ADDRESSLIST_STREET_LINE2  END)     AS CA_ADDRESSLIST_STREET_LINE2
    ,       MIN (CASE WHEN ADDRESSLIST_atyp_code = 'CA' THEN ADDRESSLIST_city     END)     AS CA_ADDRESSLIST_city
    ,       MIN (CASE WHEN ADDRESSLIST_atyp_code = 'CA' THEN ADDRESSLIST_stat_code     END)     AS CA_ADDRESSLIST_stat_code
    ,       MIN (CASE WHEN ADDRESSLIST_atyp_code = 'CA' THEN ADDRESSLIST_zip     END)     AS CA_ADDRESSLIST_zip
    
    FROM       got_rnum
    WHERE       rnum     = 1
    GROUP BY  STUINFO_last_name
    ,            STUINFO_first_name
    ,         STUINFO_id
    ORDER BY STUINFO_last_name;
    

    Max

  • Outer join does not

    Hello

    Pls help me my request. I tried the following, but it does not give the expected results.

    Tab1
    EmplId, RepDt, Code, Hrs
    1/100,1/2009,199,8
    1/100,1/2009,200,4
    1/100,1/2009,255,3
    200,1/1/2009,200,4
    100.5/1/2009,199,8


    Tab2
    EmplId, RepDt, Code, Hrs
    1/100,1/2009,200,6
    200,1/1/2009,200,3

    I need output like this - 4 rows - need of all the rows from TAB1 when EMPLID, REPDT match TAB2, field values: need at a time when Code is also, when emlid, correspondence of the date, the Code missing so need A hrs, display ZERO as Tab2 hours.

    1/100,1/2009,199,8,0 - did not exist is not in tab2, so hrs Tab2 is ZERO
    1/100,1/2009,200,4,6 - Emplid, RepDt, Code match existence in Tab2, Tab1 Hrs 8, 6 Hrs Tab2
    1/100,1/2009,255,3,0 - did not exist is not in Tab2, so Tab2 hrs is equal to ZERO
    200,1/1/2009,200,4,3 - Emplid, Repdt, Code Match existed in Tab2, 4 Hrs of Tab1, Tab2 3 Hrs

    We are in 10g, Oracle.

    I tried the following
    T1. EmplId = T2.emplid AND T1.repdt = T2.repdt AND T1.code, T2.code = (+) - returns the unique corresponding lines, 2 rows.

    Pls help.

    Thanks in advance.

    Published by: NL 23 February 2009 09:20

    Hello

    See the Boneist first message in this thread:

    select t1.emplid, t1.repdt, t1.code, t1.hrs, nvl(t2.hrs, 0)
    from   tab1 t1,
           tab2 t2
    where  t1.emplid = t2.emplid (+)
    and    t1.repdt = t2.repdt (+)
    and    t1.code = t2.code (+)
    and    (t1.emplid, t1.repdt) in (select emplid, repdt
                                     from   tab2)
    order by repdt, emplid, code;
    

    As Boneist said, this fact corresponds to option (b)
    "(b) do just an outer join, with a condition EXISTS (or IN) in the WHERE clause to find corresponding repdts.
    The

    (+)
    

    an outer join are signs.

Maybe you are looking for

  • How can I remove the firefox password reminder? It is very annoying!

    I don't want firefox continues to ask me if I want to save a password. How can I disable this rather boring?Thank you.

  • HP compaq mini PC: password

    My mini boots and it comes up enter current password.it then comes fatal error... .sytem interruptedCNU90118N5Can anyone help please.

  • HP Photosmart C6180 with abnormal shutdown Message

    My HP Photosmart C6180 began to make a loop of continuous restart with error of abnormal termination. I've now tried # and 6 at startup to do a reset, but that only solves the problem for about 30 minutes. I read on other forums on the internet that

  • Beeeping at startup

    Hello I have a brand new HP dv5-1250eo and every time I start it up it beeps this beep acute continouous. I tried to write how many beeps it was where it was a bios code, but it was continuous he has never stopped. However, if I start the computer, a

  • Problem with Vista 64-bit

    I run Vista Home Premium SP2 64 bit, to install software but one have bad message that need this 32-bit software tell me, what I can do to run this software?