Oracle left join

e.g. i have 2 table
table_a
subject
math
phy
chem
bio
table_b
subject member
math peter
phy peter
phy john
bio tim
1) i create a view as follow:
create or replace view view_test
(subject,
member)
as select a.subject,
b.member
from table_a a
left outer join table_b b
on (a.subject = b.subject)
how i can get the result from view when the sql is
select * from view_test where member = 'tim';
subject member
math
phy
chem
bio tim
i can do it in sql statment as follow;
select a.subject,
b.member
from table_a a
left outer join table_b b
on (a.subject = b.subject and
b.member = 'tim')

What part of it doesn't work for you?
SQL> SELECT * FROM tablea;
SUBJECT
math
phy
chem
bio
SQL> SELECT * FROM tableb;
SUBJECT    MEMBER
math       peter
phy        peter
phy        john
bio        tim
SQL> CREATE VIEW view_test AS
  2  SELECT a.subject, b.member
  3  FROM tablea a
  4       LEFT OUTER JOIN tableb b
  5       ON (a.subject = b.subject);
View created.
SQL> SELECT *
  2  FROM view_test
  3  WHERE member = 'tim';
SUBJECT    MEMBER
bio        timJohn

Similar Messages

  • How To do a LEFT JOIN in Oracle 8i

    Hello
    To explain my problem in a simple way: I have two tables, PROVA1 and PROVA2. Both have a primary key with two fields (CHIAVE1 amd CHIAVE2, numbers).
    I have to search for all records in A but not in B. In Oracle 8 LEFT JOIN is not available and I do not Know how doing it.
    I have read something about + operator, but I am not sure. What about:
    Select * from PROVA1 P1, PROVA2 P2 where
    (P1.CHIAVE1(+) = P2.CHIAVE1) and
    (P1.CHIAVE2(+) = P2.CHIAVE2) and
    (P2.CHIAVE1 IS NULL) and
    (P2.CHIAVE2 IS NULL)
    Thank you
    Garetano Recchi

    Gaetano, you're really close.
    The (+) sign goes near to the table where the records can be missed. In your example near P2 columns.
    Select *
      from PROVA1  P1,  PROVA2  P2
      where P1.CHIAVE1 = P2.CHIAVE1(+)
      and P1.CHIAVE2 = P2.CHIAVE2(+)
      and P2.CHIAVE1 IS NULL
      and P2.CHIAVE2 IS NULLYou can anyway use the minus operator
    Select *
      from PROVA1
      where (chiave1,chiave2) in (select chiave1, chiave2 from prova1 minus select chiave1, chiave2 from prova2);If you want to download a free book (in italiano) for oracle beginners go to
    My Oracle-related blog
    Max

  • How do u write a LEFT JOIN in Oracle Developer Forms 6i?

    I have 2 tables:PERSDET and EMP_MEDICAL_LTA
    PERSDET has EMP_ID,EMP_NAME n some other fields.
    EMP_MEDICAL_LTA has EMP_ID,FIELD1,FIELD2 n some other fields
    EMP_ID is the common field between these 2 tables.
    My requirement is to display all the EMP_NAME,that is-EMP_NAME which have field1 and field2 entries, as well as EMP_NAME which donot have field1 and field2 entries. I thought of using a LEFT join for this operation. The query I used is as follows:
    SELECT PERSDET.emp_id,PERSDET.emp_name,EMP_MEDICAL_LTA.field1,EMP_MEDICAL_LTA.field2 into emp_id,emp_name,m,l FROM
    PERSDET LEFT JOIN EMP_MEDICAL_LTA ON PERSDET.emp_id=EMP_MEDICAL_LTA.EMP_ID
    where …<some other joining conditions>;
    This query worked perfectly fine when I tried it running on the SQL prompt, but when I wrote it in a cursor in Oracle Forms 6i, it gave an error on the “LEFT” keyword!
    Is there any substitute for LEFT JOIN in Oracle Forms 6i???
    Please help!
    Thanks!

    hi,
    yes it is very much possible. and you query willbe as follows;
    SELECT PERSDET.emp_id,PERSDET.emp_name,EMP_MEDICAL_LTA.field1,EMP_MEDICAL_LTA.field2 into emp_id,emp_name,m,l FROM
    PERSDET where PERSDET.emp_id=EMP_MEDICAL_LTA.EMP_ID(+)
    where …<some other joining conditions>;
    yse, you just have to use (+) symble on the side where the join condition is not fullfilled. the 2 possibilites for your qury is PERSDET.emp_id=EMP_MEDICAL_LTA.EMP_ID(+)
    PERSDET.emp_id(+)=EMP_MEDICAL_LTA.EMP_ID
    you can execute both and suit your self.
    MohibMaan.

  • Oracle 8i, left join with conditional

    Coming from the MySQL world, I'm trying to do a left join with a
    condition:
    select c.givenname,c.surname,c.userid,r.letternr
    from cand c,responses r
    where (c.userid=r.username(+))
    and
    c.activeprofile=1
    No problem whatsoever.
    If there is no corresponding "response" in R for a given
    candidate, I get a NULL return for R.letternr.
    However, there is a flag in R, called "VISIBLE" that I wish to
    use to mean "Don't count this entry in R". R.VISIBLE=0 means
    that the response is not active/present/visible/valid.
    Am I making any sense? :-)

    If you don't want to display a row with a null value for
    r.letternr when r.visible = 0, then:
    SELECT     c.givenname,
               c.surname,
               c.userid,
               r.letternr
    FROM       cand c,
               responses r
    WHERE      c.userid = r.username (+)
    AND        c.activeprofile = 1
    AND        r.visible != 0
    Or, if you do want to display a row with a null value for
    r.letternr when r.visible = 0, then:
    SELECT     c.givenname,
               c.surname,
               c.userid,
               r.letternr
    FROM       cand c,
               responses r
    WHERE      c.userid = r.username (+)
    AND        c.activeprofile = 1
    AND        r.visible (+) != 0

  • Left Join query: revisited... I have to explain at user meeting tomm. pls..

    Hi Everyone,
    Can someone pls shed some light on the situation below
    I am understanding alot of what Michael and Rod wrote.... with my prev. post of LEFT JOIN and testing for
    not null and doing a double Boolean OR etc.
    - but- AM NOT understanding why the IS NOT NULL works, without the double boolean OR
    Pls help... have to explain what left join means to user tomm. I'm going to demo the query below and
    not the one with the double boolean OR bec. maybe too much info to present at one sitting. tx, sandra
    =====================
    the query below is left joining the STUDENT table to
    HOLD table.
    The HOLD table - contains rows for students who have holds on their record.
    a student can have more than one hold (health, HIPAA, basic life saving course)
    BUT, for this query: I'm only interested that a hold exists, so I'm choosing MAX on hold desc.
    Selecting a MAX, helps me, bec. it reduces my join to a 1 to 1 relationship, instead of
    1 to many relationship.
    Before I posted this thread at all, the LEFT JOIN below testing for IS NOT NULL worked w/o
    me having to code IS NOT NULL twice....
    Is that because, what's happening "behind the scenes" is that a temporary table containing all max rows is being
    created, for which Discoverer has no predefined join instructions, so it's letting me do a LEFT JOIN and have
    the IS NOT NULL condition.
    I would so appreciate clarification. I have a meeting on Tues, for which I have to explain LEFT JOINS to the user
    and how they should create a query. I need to come up with rules.
    If I feel "clear", I asked my boss to buy Camtasia videocast software to create a training clip for user to follow.
    Also, if any Banner user would like me to email the DIS query to run on their machine, I would be glad to do so.
    thx sooo much, Sandra
    SELECT O100384.ACADEMIC_PERIOD, O100255.ID, O100384.ID, O100255.NAME, O100384.NAME, O100255.PERSON_UID, O100384.PERSON_UID, MAX(O100255.HOLD_DESC)
    FROM ODSMGR.HOLD O100255, ODSMGR.STUDENT O100384
    WHERE ( ( O100384.PERSON_UID = O100255.PERSON_UID(+) ) ) AND ( O100384.ACADEMIC_PERIOD = '200820' )
    GROUP BY O100384.ACADEMIC_PERIOD, O100255.ID, O100384.ID, O100255.NAME, O100384.NAME, O100255.PERSON_UID, O100384.PERSON_UID
    HAVING ( ( MAX(O100255.HOLD_DESC(+)) ) IS NOT NULL )
    ORDER BY O100384.NAME ASC

    Hi,
    OK, I will try to explain this. When you outer join table B to table A then the rows in table A which do not match any rows in table B will returned with NULL in the columns from the table B.
    Oracle uses the syntax ( +) for outer joins. Now if you add another condition using the ( +) syntax (as shown below) the condition will be processed before the table is joined. Therefore if table A does not match any rows in table B which have col2=1 then the row from table A will be returned with NULLs for the table B columns.
    SELECT A.col1, B.col1
    FROM A, B
    WHERE A.col1 = B.col1( +)
    AND B.col2( +)=1
    Now, if the condition B.col2=1 was used instead then the condition would be processed after the join and therefore the rows from table A that were joined to table B but did not meet the condition would not be returned by the query.
    This applies to a WHERE clause and to the HAVING clause, but with one exception. If you use the ( +) within a group function in a HAVING clause then the ( +) will have no affect because the condition must be processed after group by and group by can only be processed after the join. Therefore MAX(B.col2( +)) = 1 is processed after the join even through it uses the ( +) syntax.
    You cannot use an OR or an IN with the ( +) syntax because the meaning of the OR in this situation is ambiguous, is the OR done before or after the join. A query with an OR or IN in an outer will fail with an Oracle ORA-01719 error. Discoverer recognises this situation and removes the ( +) so that the error does not occur. However, without the ( +) the conditions are processed after the join.
    Using the ( +) with IS NULL, e.g. col2( +) IS NOT NULL works in the same way. You just have to remember that the col2( +) could be NULL as a result of the outer join and therefore if the condition is processed after the query then the IS NOT NULL will remove the outer joined rows.
    Hope that is clear.
    Rod West

  • LEFT Join not working

    Hi guys,
    I am not sure why the left join is not working.. when I try to use the and condition out of the left join condition. The database is relational but the requirement is for reporting. I have 2 user inputs and I should get the query results as explained below..
    Let me explain with the sample data.
    Table 1: PRTYPE (P)
    TYPEID CLASSID
    T001 CLS001
    T001 CLS002
    T001 CLS003
    T002 CLS002
    T003 CLS001
    Table 2: EMPLOYEE (E)
    EMPID NAME
    E001 Joe
    E002 Mark
    E003 Lucy
    Table 3: DETAILS (D)
    EMPID CLASSID STATUS
    E001 CLS001 NEW
    E001 CLS002 DONE
    E002 CLS001 NEW
    E002 CLS004 NEW
    Report1:
    Input: PRTYPE.TYPEID = T001, EMPID = E001
    Output:
    E.NAME E.EMPID P.TYPEID A.CLASSID D.STATUS
    JOE EMP001 T001 CLS001 NEW
    JOE EMP001 T001 CLS002 DONE
    JOE EMP001 T001 CLS003 BLANK
    Report2:
    PRTYPE.TYPEID = T003, EMPID = E003
    E.NAME E.EMPID P.TYPEID A.CLASSID D.STATUS
    LUCY E003 T003 CLS001 BLANK
    LUCY E003 T003 CLS004 BLANK
    When I use and condition in left join itself, it works but when I take it to the end of the sql using where p.typeid= T001 and E.EMPID = E001 I am not getting the left join results... It looks like Oracle doesn't like the condition at the end. I hope I am clear on explaining. Please share your experience on how to get it working..
    Thank you

    Hi,
    Welcome to the forum!
    user12118328 wrote:
    I am not sure why the left join is not working.. when I try to use the and condition out of the left join condition. The database is relational but the requirement is for reporting. I have 2 user inputs and I should get the query results as explained below..
    When I use and condition in left join itself, it works but when I take it to the end of the sql using where p.typeid= T001 and E.EMPID = E001 I am not getting the left join results... It looks like Oracle doesn't like the condition at the end. I hope I am clear on explaining. Please share your experience on how to get it working..I'm not sure what you mean. Why don't you post your query? You know, it will be easier for someone to tell you what you're doing wrong if they know what you're doing.
    Are you saying that you get the correct results when you have a cerain condition in an outer join, but that you get the wrong results if you put the exact same condition in the WHERE-clause?
    If so, keep the condition where it does what you want.
    You can usually move INNER join conditions around like that, but never OUTER join conditions.
    As Alex said, if you want help, post executable statement to create and populate your tables with a little sample data, as well as the output you want from that sample data, and your best attempt at a query.

  • Having issues with a left join, getting ORA-00904 error

    Ok this is something very similar to what I am facing, but dumbed down. None of these columns or tables names exist in real life (Very paranoid company I work for, understandable though) but the fundamental problem I am having is like below.
    Basically I know I could have done something similar to this is MS SQL (Or am I dreaming?). If I am right or wrong I need to know a way around this.
    Obviously if you comment out the "CAL.WEEK_SINCE_2005" and "AND CUST.week_since_2005 = CAL.WEEK_SINCE_2005" it would work. But I really need it to display the date as well. So it can be group'ed by week since 2005.
    I will be joining other statements to this. I am hoping on doing this in one select statement instead of creating multiple tables as I am now. All the other joined tables will follow a VERY similar layout to this. So something like this is need to obtain the look.
    When ran I get the following error.
    I look forward to learning what I did wrong and how I can fix it. :)
    select ORG.ORGANIZATION_NAME,
    CUST.CUST_COUNT,
    CAL.WEEK_SINCE_2005
    FROM organization ORG,
    calendar CAL
    LEFT JOIN (
    SELECT CAP.CURRENT_STORE,
    CALEN.week_since_2005,
    count(CAP.inactive_date) CUST_COUNT
    FROM CUST_AGREE_PAST CAP,
    calendar CALEN
    WHERE CAP.active_date is not null
    and CAP.inactive_code in ('T')
    and CAP.inactive_date between '01-sep-07' and sysdate
    and CAP.INACTIVE_DATE = CALEN.CALENDAR_DATE
    and CAP.RSN_CODE_ID in (select rsn_code_id from reasons where title in ('FAIL', 'NO CALL'))
    GROUP BY CAP.CURRENT_STORE,
    CALEN.week_since_2005) CUST
    ON PO.CURRENT_STORE = ORG.ORGANIZATION_NAME
    AND CUST.week_since_2005 = CAL.WEEK_SINCE_2005

    Just noticed a problem (there might be others):
    FROM organization ORG,
    calendar CAL
    LEFT JOIN (You cannot do that - you are mixing Oracle and ANSI join syntax. You have to do one or the other:
    FROM organization ORG
    JOIN calendar CAL on (ORG.col = CAL.col)
    LEFT JOIN (....)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Differences between left join in oracle8 style and oracle10g style

    Hi,
    I need some help to figure out what impact can be, on a product, the migration of query left join syntax from the Oracle8 one to the Oracle10g:
    we have a product that uses Hibernate configured to use the Oracle8 dialect to perform queries which uses the (+) sintax to perform outer join query, and we encountered a bug in that dialect that is forcing us to move on the Oracle10g dialect which uses the ANSI 92 style to perform outer join queries.
    Someone know if there are differences/bugs/incompatibilities for outer join query written using the ANSI 92 style instead the Oracle8 style like DB functions (like NVL(), DECODE(), and so on) that work in a different way using a style instead the other?
    Thanks.
    Luca.

    luca.depetrillo wrote:
    Hi,
    I need some help to figure out what impact can be, on a product, the migration of query left join syntax from the Oracle8 one to the Oracle10g:
    we have a product that uses Hibernate configured to use the Oracle8 dialect to perform queries which uses the (+) sintax to perform outer join query, and we encountered a bug in that dialect that is forcing us to move on the Oracle10g dialect which uses the ANSI 92 style to perform outer join queries.
    Someone know if there are differences/bugs/incompatibilities for outer join query written using the ANSI 92 style instead the Oracle8 style like DB functions (like NVL(), DECODE(), and so on) that work in a different way using a style instead the other?
    Thanks.
    Luca.In earlier versions of 10g (i.e. 10.1.?.?) there was a few bugs in the ANSI syntax joins on SQL, but they seemed to have sorted most of those out for 10.2.?.? onwards.
    Essentially there will be no real adverse effects in using ANSI syntax, and it shouldn't stop your other functions working.
    ANSI syntax also gives you the advantage that you can outer join to more than one table which you can't do in Oracle syntax outer joins.
    Edited by: BluShadow on Nov 18, 2008 2:06 PM
    prevented stupid forum formatting

  • How to use LEFT JOIN in LINQ

    I have this query in Oracle and I am trying to write a Linq query for this below sql. There are 2 datatables DATA_TABLE1 and DATA_TABLE2. Both tables have 2 fields ID1 and ID2.
    SELECT A.ID1, A.ID2
    FROM DATA_TABLE1 A
    LEFT JOIN DATA_TABLE2 B
    ON A.ID1 = B.ID1 AND A.ID2 = B.ID2
    WHERE B.ID1 IS NULL OR B.ID2 IS NULL

    In order to see what query the data provider sent to the server you can do the following.
    Just after creating the data context place this line in the code.
    db.Database.Log = Console.Write;
    Then place a breakpoint after the next line of code, shown next.
    var
    a =
    db.product.Where(p
    =>
    p.Name.Contains(asKeyword)).ToList();
    Then run the application and when it hits the breakpoint open the Visual Studio Output window and the SQL sent to the server should be displayed.
    Fernando (MCSD)
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects
    and unknown namespaces.

  • Oracle outer join strange results (at least for me)

    Hi there,
    I want to show you a problem I saw to a client site.
    Oracle 9.2.0.8.0
    SunOS 5.9 (but I'm unable to check installed patch)
    The query is quite simple:
    SELECT *
      FROM     (SELECT /*+ NO_MERGE */
                      DISTINCT col1,col2
                  FROM Tab1
                 WHERE status = 'L') a
           LEFT JOIN
               (SELECT col1,
                       col2,
                       1 as flag_match
                  FROM tab2 a
                 WHERE     a.action IN ('I', 'U')
                       AND NVL (a.col3, 'D') IN ('I', 'U')
                       AND NVL (a.col4, '?') NOT IN ('V', 'P', 'Q')) b
           ON (b.col1 = a.col1 AND b.col2 = a.col2)The expected result is (obvious?):
    a.Col1   a.Col2   b.Col1   b.Col2   flag_match
    X          Y         NULL    NULL     NULL
    A          B         A         B          1What we get is:
    a.Col1   a.Col2   b.Col1   b.Col2   flag_match
    X          Y         NULL    NULL     NULL
    A          B         A         B          NULLThis looks wrong to me.
    If we check with a SELECT COUNT(*) the result of the query, using something like this:
    SELECT COUINT(*) FROM (
    SELECT *
      FROM     (SELECT /*+ NO_MERGE */
                      DISTINCT col1,col2
                  FROM Tab1
                 WHERE status = 'L') a
           LEFT JOIN
               (SELECT col1,
                       col2,
                       1 as flag_match
                  FROM tab2 a
                 WHERE     a.action IN ('I', 'U')
                       AND NVL (a.col3, 'D') IN ('I', 'U')
                       AND NVL (a.col4, '?') NOT IN ('V', 'P', 'Q')) b
           ON (b.col1 = a.col1 AND b.col2 = a.col2)
    WHERE flag_match...We got these results:
    with FLAG_MATCH IS NULL, 1000 rows
    with FLAG_MATCH IS NOT NULL, 900 rows
    without the where on FLAG_MATCH, 1000 rows
    What you think? Ever seen something like this?
    Thank you in advance.
    Antonio

    Hi Antonio,
    running the query as you have posted, you should not get the result NULL under column flag_match when b.col1 is not NULL.
    Unless a bug but I doubt it.
    Could you please post some sample data to be able to reproduce the problem?
    Data can be posted also as WITH statement in this way:
    WITH tab1(col1, col2, status) AS
       SELECT 'X', 'Y', 'L' FROM DUAL UNION ALL
       SELECT 'A', 'B', 'L' FROM DUAL
    , tab2(col1, col2, col3, col4, action) as
       SELECT 'A', 'B', 'I', 'X', 'I' FROM DUAL
    SELECT *
      FROM     (SELECT /*+ NO_MERGE */
                      DISTINCT col1,col2
                  FROM Tab1
                 WHERE status = 'L') a
           LEFT JOIN
               (SELECT col1,
                       col2,
                       1 as flag_match
                  FROM tab2 a
                 WHERE     a.action IN ('I', 'U')
                       AND NVL (a.col3, 'D') IN ('I', 'U')
                       AND NVL (a.col4, '?') NOT IN ('V', 'P', 'Q')) b
           ON (b.col1 = a.col1 AND b.col2 = a.col2)
    COL1 COL2 COL1_1 COL2_1 FLAG_MATCH
    A    B    A      B               1
    X    Y                            Also try to execute the statement above to see if you are experiencing the same problem.
    Edit:
    I've seen the second part of your post:
    with FLAG_MATCH IS NULL, 1000 rows
    with FLAG_MATCH IS NOT NULL, 900 rows
    without the where on FLAG_MATCH, 1000 rowsand I have to say that is looks like a bug. Could you try grouping by flag_match?
    SELECT flag_match, COUNT(*) FROM (
    SELECT *
      FROM     (SELECT /*+ NO_MERGE */
                      DISTINCT col1,col2
                  FROM Tab1
                 WHERE status = 'L') a
           LEFT JOIN
               (SELECT col1,
                       col2,
                       1 as flag_match
                  FROM tab2 a
                 WHERE     a.action IN ('I', 'U')
                       AND NVL (a.col3, 'D') IN ('I', 'U')
                       AND NVL (a.col4, '?') NOT IN ('V', 'P', 'Q')) b
           ON (b.col1 = a.col1 AND b.col2 = a.col2)
    GROUP by flag_matchRegards.
    Al
    Edited by: Alberto Faenza on Dec 18, 2012 2:49 PM

  • 3 tables with left joins - bug?

    Hello,
    i am making query where i encounter problem with left join in oracle. I am using oracle 10g and i prepare simple test case.
    he is testing tables and datas - really simple i think:
    drop table t1;
    drop table t2;
    drop table t3;
    create table t1 (a number not null);
    create table t2 (a number, b number);
    create table t3 (b number);
    insert into t3 values (1);
    insert into t3 values (2);
    insert into t3 values (3);
    insert into t1 (a) values (1);
    insert into t2 (a,b) values (1,1);
    insert into t1 (a) values (2);
    insert into t2 (a,b) values (2, null);
    insert into t1 (a) values (3);
    insert into t1 (a) values (4);
    insert into t2 (a,b) values (4,1);
    insert into t1 (a) values (5);
    insert into t2 (a,b) values (5,3);
    and now query with left joins:
    select
    t1.a
    , t2.a, t2.b
    , t3.b
    from
    t1, t2, t3
    where
    t1.a = t2.a (+)
    and t2.b = t3.b (+)
    and t3.b is null
    order by t1.a
    i get two rows as result:
    A A_1 B B_1
    2 2 null null      
    3 null null null                
    i expect these rows but when i change my query - i dont want get back t3.b column:
    select
    t1.a
    , t2.a, t2.b
    /* , t3.b*/
    from
    t1, t2, t3
    where
    t1.a = t2.a (+)
    and t2.b = t3.b (+)
    and t3.b is null
    order by t1.a
    i get only one row
    A A_1 B
    2 2 null
    My question is simple how can i only by changing columns getting back change number of returned rows? I must say i dont expect these result i expect two rows again.
    Thanks for help.

    BluShadow wrote:
    I think I know what you are getting at.
    By testing for null on t3.b when you aren't selecting the column, you are enforcing oracle to perform the join through t2 onto t1, but Oracle can't join because t2 has no matching row (although it's outer joined to t1) and therefore, for the one row it can't actually determine if t3.b is null or not, so that row can't match the conditions in a "true" sense and be displayed. If you select the column then oracle can test its nullness ok. (Perhaps this is a bug, I don't know, it's just how I know it works)If you get different results only by changing the projection part of the query this is a bug and nothing else. I can't reproduce using Oracle 10g XE, I get in both cases shown the expected two rows.
    What versions are you using to test this?
    SQL>
    SQL> select * from v$version
      2  where rownum <= 1;
    BANNER
    Oracle Database 10g Express Edition Release 10.2.0.1.0 - Product
    SQL>
    SQL> drop table t1 purge;
    Table dropped.
    SQL> drop table t2 purge;
    Table dropped.
    SQL> drop table t3 purge;
    Table dropped.
    SQL>
    SQL> create table t1 (a number not null);
    Table created.
    SQL> create table t2 (a number, b number);
    Table created.
    SQL> create table t3 (b number);
    Table created.
    SQL>
    SQL> insert into t3 values (1);
    1 row created.
    SQL> insert into t3 values (2);
    1 row created.
    SQL> insert into t3 values (3);
    1 row created.
    SQL>
    SQL> insert into t1 (a) values (1);
    1 row created.
    SQL> insert into t2 (a,b) values (1,1);
    1 row created.
    SQL>
    SQL> insert into t1 (a) values (2);
    1 row created.
    SQL> insert into t2 (a,b) values (2, null);
    1 row created.
    SQL>
    SQL> insert into t1 (a) values (3);
    1 row created.
    SQL>
    SQL> insert into t1 (a) values (4);
    1 row created.
    SQL> insert into t2 (a,b) values (4,1);
    1 row created.
    SQL>
    SQL> insert into t1 (a) values (5);
    1 row created.
    SQL> insert into t2 (a,b) values (5,3);
    1 row created.
    SQL>
    SQL> commit;
    Commit complete.
    SQL>
    SQL> select t1.a
      2       , t2.a, t2.b
      3       , t3.b
      4  from
      5         t1 left outer join t2 on (t1.a = t2.a)
      6            left outer join t3 on (t2.b = t3.b)
      7  where t3.b is null
      8  order by t1.a;
             A          A          B          B
             2          2
             3
    SQL>
    SQL> select t1.a
      2       , t2.a, t2.b
      3  --     , t3.b
      4  from
      5         t1 left outer join t2 on (t1.a = t2.a)
      6            left outer join t3 on (t2.b = t3.b)
      7  where t3.b is null
      8  order by t1.a;
             A          A          B
             2          2
             3
    SQL>Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

  • Inconsistent results with ANSI LEFT JOIN on 9iR2

    Is this a known issue? Is it solved in 10g?
    With the following data setup, I get inconsistent results. It seems to be linked to the combination of using LEFT JOIN with the NULL comparison within the JOIN.
    create table titles (title_id int, title varchar(50));
    insert into titles values (1, 'Red Book');
    insert into titles values (2, 'Yellow Book');
    insert into titles values (3, 'Blue Book');
    insert into titles values (4, 'Orange Book');
    create table sales (stor_id int, title_id int, qty int, email varchar(60));
    insert into sales values (1, 1, 1, '[email protected]'));
    insert into sales values (1, 2, 1, '[email protected]');
    insert into sales values (3, 3, 4, null);
    insert into sales values (3, 4, 5, '[email protected]');
    SQL&gt; SELECT titles.title_id, title, qty
    2 FROM titles LEFT OUTER JOIN sales
    3 ON titles.title_id = sales.title_id
    4 AND stor_id = 3
    5 AND sales.email is not null
    6 ;
    TITLE_ID TITLE QTY
    4 Orange Book 5
    3 Blue Book
    1 Red Book
    2 Yellow Book
    SQL&gt;
    SQL&gt; SELECT titles.title_id, title, qty
    2 FROM titles LEFT OUTER JOIN sales
    3 ON titles.title_id = sales.title_id
    4 AND 3 = stor_id
    5 AND sales.email is not null;
    TITLE_ID TITLE QTY
    2 Yellow Book 1
    4 Orange Book 5
    3 Blue Book
    1 Red Book
    It seems to matter what order I specify the operands stor_id = 3, or 3 = stor_id.
    In the older (+) environment, I would understand this, but here? I'm pretty sure most other databases don't care about the order.
    thanks for your insight
    Kevin

    Don't have a 9i around right now to test ... but in 10 ...
    SQL> create table titles (title_id int, title varchar(50));
     
    Table created.
     
    SQL> insert into titles values (1, 'Red Book');
     
    1 row created.
     
    SQL> insert into titles values (2, 'Yellow Book');
     
    1 row created.
     
    SQL> insert into titles values (3, 'Blue Book');
     
    1 row created.
     
    SQL> insert into titles values (4, 'Orange Book');
     
    1 row created.
     
    SQL> create table sales (stor_id int, title_id int, qty int, email varchar(60));
     
    Table created.
     
    SQL> insert into sales values (1, 1, 1, '[email protected]');
     
    1 row created.
     
    SQL> insert into sales values (1, 2, 1, '[email protected]');
     
    1 row created.
     
    SQL> insert into sales values (3, 3, 4, null);
     
    1 row created.
     
    SQL> insert into sales values (3, 4, 5, '[email protected]');
     
    1 row created.
     
    SQL> SELECT titles.title_id, title, qty
      2   FROM titles LEFT OUTER JOIN sales
      3   ON titles.title_id = sales.title_id
      4   AND stor_id = 3
      5   AND sales.email is not null
      6   ;
     
      TITLE_ID TITLE                                                     QTY
             4 Orange Book                                                 5
             3 Blue Book
             1 Red Book
             2 Yellow Book
     
    SQL>
    SQL> SELECT titles.title_id, title, qty
      2   FROM titles LEFT OUTER JOIN sales
      3   ON titles.title_id = sales.title_id
      4   AND 3 = stor_id
      5   AND sales.email is not null;
     
      TITLE_ID TITLE                                                     QTY
             4 Orange Book                                                 5
             3 Blue Book
             1 Red Book
             2 Yellow Book
    SQL> exit
    Disconnected from Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - Production
    With the Partitioning, OLAP and Data Mining options

  • Left join problem

    hi guys,
    please see this query once.
    in 3rd left join i am getting error like subqueries not allowed here.
    can you help me to reslove this.
    SELECT
    '20060201'||d.acct_num as user_ref_area,
    ind.name_first||' ' ||ind.name_last AS full_name,
    PA.ADDR_FIRST_LINE,
    PA.CITY_NAME||','||
    PA.STATE_ABBR as city_state,
    PA.ZIP_CDE AS zip_cde,
    CASE WHEN iphr.pho_stat_cde ='G' THEN
    '000'||pha.pho_exchg_num||pha.pho_line_num
    ELSE '0000000000'
    END AS home_phone,
    ind.ss_num,
    d.activity_date,
    d.acct_num
    FROM (
    select j.acct_num,j.activity_date
    from (
    select dxr.acct_num,
    to_char(o3.o3bfct) as activity_date
    from debtp.o3
    JOIN debtp.acct_xref dxr
    ON o3.o3e5cd = dxr.e5cd
    WHERE o3dhce in ('aj','ja','ta')
    AND load_dt >=to_date('2006/01/28','yyyy/mm/dd')-- trunc(sysdate-4) --NEED TO USE SYSDATE-4                                        
    UNION
    select account_number,TO_CHAR(data_date, 'YYYYMMDD') as activitydate
    from clctdm.triad_history
    where data_date =to_date('2006/01/31','yyyy/mm/dd')--trunc(sysdate-1) --NEED TO USE SYSDATE-1
    and delq_coll_ind in ('960','961','962','963')
    ) j
    left join
    select ACCT_NUM
    from hbivt1.pp_fd_accts FDAI
    where FDAI.DATE_activity >='20060102'--to_char(trunc(add_months(sysdate,-1)),'yyyymmdd')
    ) k
    on j.acct_num =k.acct_num
    where k.acct_num IS null
    ) d
    JOIN AUTOR3.ACCT_XREF XR --lookup for arr_id_acct values
    ON d.acct_num =xr.acct_num
    JOIN AUTOR3.ARR_IP_POSTL_REL AIPL --lookup for postl_addr_id
    ON AIPL.ARR_ID = XR.ARR_ID_ACCT
    and aipl.actv_ind ='0'
    join autor3s.indv ind --table with values for FIRSTDATA
    on aipl.hi_num =ind.hi_num_indv
    Left JOIN AUTOR3s.POSTL_ADDR PA ----table with values for FIRSTDATA
    ON aipl.POSTL_ADDR_ID = PA.POSTL_ADDR_ID
    left join autor3.ip_pho_rel iphr
    on iphr.hi_num =aipl.hi_num and
    start_dt_tm =(
    select max(iphr2.start_dt_tm) as start_dt_tm from AUTOR3.IP_PHO_REL IPHR2
    WHERE iphr2.rank_num='1'
    and iphr2.ip_pho_rel_cde='001000'
    and iphr2.actv_ind='0'
    and iphr2.hi_num =aipl.hi_num
    )

    Oracle only supports outer joins as extended equalities.
    You'll have to use the syntax:
    FROM PC2KAUDIT,AUDITDETAIL
    WHERE
    ... (other where clause)
    AND
    PC2KAUDIT.AUDITID = AUDITDETAIL.AUDITID (+)
    This will do basically the same thing. Unfortunately there is no common syntax, unless oyu have a fancy ODBC driver, which might do this translation for you.
    null

  • Left join from different database

    Hi,
    I had a scenario where I need to write a query that gets records from SQL Server Database but having a left join on Oracle table, I know we can achiev this through DB link between Oracle and SQL but my DB team are not willing to create DB links, Is there a way probably from Data Templates we can write a query which can call Oracle table too?

    Hi
    Thanks for your reply, but my situation is I do not have two queries, I have a single query which is pulling columns from SQL server based on a left join on one of the column of Oracle Table (cURRENTLY THERE IS db LINK BETWEEN TWO).
    For E.g.
    SELECT customers.first_name,customers.last_name from customers,orders
    Where
    Customers.Order_ID=Orders.Order_ID,
    The situation here is suppose the Orders is in Oracle DB and Customers in the SQL Server DB, How am I gonna achieve this using BI publisher If I do not have DB link.

  • JPA OnetoMany  QUERY LEFT JOIN BUG

    Using JPA in JDev 10.1.3.1.0.3984
    Database: Firebird 1.51LI-V1.5.3.4870 Firebird 1.5/tcp
    Driver: Jaybird JCA/JDBC driver Version: 2.1
    TopLink, version: Oracle TopLink Essentials - 2006.8 (Build 060829)
    If I use normal JOIN it works.
    On LEFT JOIN I get a {oj [/b] before the table name and a [b]} at the end.
    public class Cliente{
        @OneToMany(mappedBy = "cliente")
        @JoinColumn(name = "CDCLIENTE", referencedColumnName = "CDCLIENTEREQUISITANTE")
        private List<Requisicao> requisicoes;
    public class Requisicao
        @ManyToOne
        @JoinColumn(name = "CDCLIENTEREQUISITANTE", referencedColumnName = "CDCLIENTE")
        private Cliente cliente;
    EntityManager em = getEntityManager();
    String sql = "SELECT c FROM Cliente c LEFT JOIN c.requisicoes req";
    Query q = em.createQuery(sql);
    List rs = q.getResultList();Result SQL:
    SELECT DISTINCT t0. <OMITTED> FROM {oj [/b]CLIENTE t0 LEFT OUTER JOIN REQUISICAO t1 ON (t1.CDCLIENTEREQUISITANTE = t0.CDCLIENTE)[b]}

    You cannot define an ON clause with Criteria, nor JPQL.
    Perhaps you can reword the query to avoid needing an ON clause.
    What is the query you want to do (in english)?
    Can you just use an OR in the where clause?
    There is a enhancement request to have ON clause support added, please vote for it.
    https://bugs.eclipse.org/bugs/show_bug.cgi?id=312146
    James : http://www.eclipselink.org

Maybe you are looking for

  • Flash Player requires "Kick start" to play video contents

    Am presently Flash Player 11.5.502.146 on Windows 7 64 Bit with Firefox 18.0.1. I have been having a rather odd occurence.  When I go to youtube.com and select a video, all I get is a black box with no controls and nothing happens. (This also happens

  • Activate ODS

    Hi All I made the mistake of removing the BEX Reporting indicator from an ODS because the reports were being run off a Multiprovider rather than the ODS I thought this would improve load performance. There are roughly 12m records that we've split up

  • Loading external files?

    Hi guys, Sorry to sound such a newbie, but just wondering if anybody can direct me to the right path, basically i need to make a GUI in java, i know i can do this using Jbutton etc but how can i for example by clicking on a button load a SWF file int

  • Set page break after a number of rows

    I am trying to set the page break of a table to occur every 200 rows. By default it generates a page break once the report size grows larger than the page length. When I set the property KeepTogether = true, it no longer generates the page breaks but

  • Can I log outside dynamic IP address with 871?

    I'm looking to clean up some web traffic analysis on a remote server. Can I log the changing outside dynamic IP my router is assigned to?