Does CFSQL Not Do Left Joins?

Hello. The following syntax works fine inside a
<CFQUERY> statement getting data from an ODBC database (where
JobList and Reported are tables in the datasource named in the
CFQUERY statement):
select * from JobList j left join Reported r on j.job_no =
r.jobno
However, it does not work when embedded inside a
<CFQUERY> statement trying to join two existing queries (i.e.
dbtype = 'QUERY', where JobList and Reported are the names of the
existing queries.
Instead I receive the error message:
Query Of Queries syntax error. Encountered "j.
If I remove the j and r aliases and go with select * from
JobList left join Reported on JobList.job_no = Reported.jobno, I
receive the error message:
Query Of Queries syntax error. Encountered "left
It does not help matters to add the word 'outer' after the
word 'left'.
Should I be using a different syntax, or does CFSQL simply
not do outer joins? The documentation says it does joins, but
provided no examples.
If CFSQL simply cannot to outer joins, am I stuck? The two
tables to be joined ultimately reside in completely different DB's:
FoxPro and SQL Server.
Thanks for your help.

Using
joins - Q-of-Q
Using joins
A join operation uses a single SELECT statement to return a
result set from multiple, related tables, typically those with a
primary key - foreign key relationship. There are two SQL clauses
that perform joins:
WHERE clause ColdFusion supports joins through a WHERE
clause.
INNER JOIN and OUTER JOIN ColdFusion
does not support joins through INNER JOIN or OUTER JOIN
clauses.
Note: Query of Queries supports joins between two tables
only.
FYI, you can sometimes accomplish your OUTER JOINs by using
UNIONs as a work around.
Phil

Similar Messages

  • Left joins on multi-million rows

    i have a simple query doing left joining on several tables, upward of 7 tables. each table has several hundred million rows.
    tblA is 1:M tblB and tblB is 1:M tblC and so on.
    how to tune a query liked that?
    sample query is
    select distinct
    a.col,b.col,c.col
    from tblA a left join tblB b
    on a.id=b.id
    and a.col is not null
    left join tblC
    on b.id=c.id
    and c.col > criteria
    thanks.

    hi
    a simple query is liked
    SELECT my_DEP.description,
    my_DEP.addr_id,
    hundredRowsTbl.address,
    5MillTbl.checkin_TIME,
    5MillTbl.checkout_TIME,
    hundredRowsTbl.ID2,
    5MillTbl.ID,
    5MillTbl.col2,
    my_DEP.col3,
    5MillTbl.col13,
    hundreds.desc,
    50mmTbl.col6,
    50mmTbl.col5,
    5MillTbl.col33
    FROM
    my.5MillTbl 5MillTbl
    LEFT OUTER JOIN
    my.50mmTbl 50mmTbl
    ON 5MillTbl.ID = 50mmTbl.ID
    LEFT OUTER JOIN my.hundreds hundreds
    ON 5MillTbl.banding =
    hundreds.banding
    INNER JOIN my.my_DEP my_DEP
    ON 5MillTbl.organization_ID = my_DEP.organization_ID
    INNER JOIN my.my_40millTbl
    ON 5MillTbl.seqID = my_40millTbl.seqID
    LEFT OUTER JOIN my.hundredRowsTbl hundredRowsTbl
    ON my_DEP.addr_id = hundredRowsTbl.ID2
    LEFT OUTER JOIN my.30millTbl 30millTbl
    ON my_DEP.organization_ID = 30millTbl.dept_id
    WHERE 1=1
    AND 5MillTbl.ID IS NOT NULL
    AND ( 5MillTbl.checkout_TIME >= TO_DATE ('01-01-2009 00:00:00', 'DD-MM-YYYY HH24:MI:SS')
    AND 5MillTbl.checkout_TIME <TO_DATE ('12-31-2010 00:00:00', 'DD-MM-YYYY HH24:MI:SS')
    AND ( 5MillTbl.col2 IS NULL
    OR NOT (5MillTbl.col2 = 5
    OR 5MillTbl.col2 = 6)
    AND 5MillTbl.ID IS NOT NULL
    AND 30millTbl.TYPE= '30'
    AND my_DEP.addr_id = 61

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

  • Left join (+) instead of "not in"

    Hi all!
    I've got statement with "where dig not in (840, 978)" string.
    How do I write statement without "not in" ?
    I thought about left join and "is not null", but don't know exactly how to use it.
    Any ideas?
    Thanks ahead.

    Here is my solution:
    select d.* from
    (select 111 as accountno, 840 as currencyid from dual
    union all
    select 222 as accountno, 978 as currencyid from dual
    union all
    select 333 as accountno, 826 as currencyid from dual ) d ,
    (select 840 as dig from dual
    union all
    select 978 as dig from dual ) j
    where d.currencyid = j.dig(+)
    and j.dig is null
    Thanks to all.

  • Testing for IS NOT NULL with left join tables

    Dear Experts,
    The query is showing the NULL rows in the query below....
    Any ideas, advice please? tx, sandra
    This is the sql inspector:
    SELECT O100321.FULL_NAME_LFMI, O100321.ID, O100404.ID, O100321.ID_SOURCE
    , O100404.NAME, O100321.PERSON_UID, O100404.PERSON_UID, O100404.VISA_TYPE
    FROM ODSMGR.PERSON O100321
    , ODSMGR.VISA O100404
    WHERE ( ( O100321.PERSON_UID = O100404.PERSON_UID(+) ) ) AND ( O100404.VISA_TYPE(+) IS NOT NULL )

    Hi Everyone,
    I am understanding alot of what Michael and Rod wrote.... I am just puzzled over the following:
    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

  • Left join and where clause with not equal ( ) returns too many rows

    Say I have something like this
    Table A
    =========
    Id
    OrderNum
    Date
    StoreName
    AddressKey
    Table B
    ========
    Id
    StreetNumber
    City
    State
    select a.* from [Table A] a
    left join [Table B] b on a.AddressKey = b.Id
    where a.StoreName <> 'Burger place'
    The trouble is that the above query still returns rows that have StoreName = 'Burger place'
    One way Ive handled this is to use a table expression, select everything into that, then select from the CTE and apply the filter there.  How could you handle it in the same query however?

    Hi Joe,
    Thanks for your notes.
    INT SURROGATE PRIMARY KEY provides a small footprint JOIN ON column. Hence performance gain and simple JOIN programming.  In the Addresses table, address_id is 4 bytes as opposed to 15 bytes san. Similarly for the Orders table.
    INT SURROGATE PRIMARY KEY is a meaningless number which can be duplicated at will in other tables as FOREIGN KEY.  Having a meaningful PRIMARY KEY violates the RDBMS basics about avoiding data duplication.  If I make CelebrityName (Frank Sinatra)
    a PRIMARY KEY, I have to duplicate "Frank Sinatra" as an FK wherever it needed as opposed to duplicating SURROGATE PRIMARY KEY CelebrityID (79) a meaningless number.
    This is how we design in SQL Server world.
    QUOTE from Wiki: "
    Advantages[edit]
    Immutability[edit]
    Surrogate keys do not change while the row exists. This has the following advantages:
    Applications cannot lose their reference to a row in the database (since the identifier never changes).
    The primary or natural key data can always be modified, even with databases that do not support cascading updates across related
    foreign keys.
    Requirement changes[edit]
    Attributes that uniquely identify an entity might change, which might invalidate the suitability of natural keys. Consider the following example:
    An employee's network user name is chosen as a natural key. Upon merging with another company, new employees must be inserted. Some of the new network user names create conflicts because their user names were generated independently (when the companies
    were separate).
    In these cases, generally a new attribute must be added to the natural key (for example, an
    original_company column). With a surrogate key, only the table that defines the surrogate key must be changed. With natural keys, all tables (and possibly other, related software) that use the natural key will have to change.
    Some problem domains do not clearly identify a suitable natural key. Surrogate key avoids choosing a natural key that might be incorrect.
    Performance[edit]
    Surrogate keys tend to be a compact data type, such as a four-byte integer. This allows the database to query the single key column faster than it could multiple columns. Furthermore a non-redundant distribution of keys causes the resulting
    b-tree index to be completely balanced. Surrogate keys are also less expensive to join (fewer columns to compare) than
    compound keys.
    Compatibility[edit]
    While using several database application development systems, drivers, and
    object-relational mapping systems, such as
    Ruby on Rails or
    Hibernate, it is much easier to use an integer or GUID surrogate keys for every table instead of natural keys in order to support database-system-agnostic operations and object-to-row mapping.
    Uniformity[edit]
    When every table has a uniform surrogate key, some tasks can be easily automated by writing the code in a table-independent way.
    Validation[edit]
    It is possible to design key-values that follow a well-known pattern or structure which can be automatically verified. For instance, the keys that are intended to be used in some column of some table might be designed to "look differently from"
    those that are intended to be used in another column or table, thereby simplifying the detection of application errors in which the keys have been misplaced. However, this characteristic of the surrogate keys should never be used to drive any of the logic
    of the applications themselves, as this would violate the principles of
    Database normalization"
    LINK: http://en.wikipedia.org/wiki/Surrogate_key
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Database Design
    New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2014

  • ORA-02070 database does not support semi join in this context

    The following merge sql on Oracle 11g throws "ORA-02070 database does not support semi join in this context".
    MERGE INTO ORDERS tgt
    USING
    SELECT C.short_name, C.customer_id
    FROM customers C
    WHERE customer_id IN ( SELECT distinct customer id FROM orders O WHERE O.order_date > SYSDATE - 3 )
    )src
    ON ( tgt.customer_id=src.customer_id )
    WHEN MATCHED THEN
    UPDATE SET tgt.short_name=src.short_name;
    Any ideas? This piece of code was working on an earlier version of Oracle 11g.
    Thanks,
    Anu

    Hi, Anu,
    You can try this:
    MERGE INTO ORDERS     tgt
    USING
            SELECT  C.short_name, C.customer_id
         FROM      customers C
    )                src
    ON (     tgt.customer_id = src.customer_id
       AND     tgt.order_date     > SYSDATE - 3
    WHEN MATCHED THEN
         UPDATE  SET     tgt.short_name = src.short_name; It's surprising that the error message mentioned a semi-join, because you weren't doing a semi-join. An example of a semi-join is:
    MERGE INTO ORDERS     tgt
    USING
            SELECT DISTINCT
                   C.short_name, C.customer_id
         FROM        customers C
         JOIN       orders    o     ON  c.customer_id  = o.customer_id
         WHERE       o.order_date     > SYSDATE - 3
    )                src
    ON (tgt.customer_id = src.customer_id)
    WHEN MATCHED THEN
         UPDATE  SET     tgt.short_name = src.short_name; but perhaps the optimizer re-wrote your IN sub-query as a semi-join.
    An EXISTS sub-query is another way to get the results you want, unless it causes ORA-02070, also. Natrually, I can't test anythihng, since you didn't post any sample data.
    Edited by: Frank Kulash on Apr 5, 2011 11:34 AM

  • My iPhone 5 will not sync with itunes. Icon does no appear in left hand column. Both iTunes and the iPhone are running the most up to date updates. Please help.

    My iPhone 5 will not sync with itunes. Icon does no appear in left hand column. Both iTunes and the iPhone are running the most up to date updates. Please help.

    Is your iPhone connected to your computer using the lightning cable or are you doing WiFi sync?
    Sometimes the iPhone doesn't show up in the side bar if you're using WiFi syncing, if its not working, then be connected to your WiFi on your phone and on your computer (Same network) let me know how it's going, if it doesn't work still. Turn your phone off and on again and put in your pass code then try to sync it (keep your phone unlocked and not in sleep mode) tel me if it appears in the side bar.

  • Does anyone know possible reasons a left join in the forge would drop the entire record?

    Hi All,
    I'm trying to join some data on to my records in the forge using a left join and no matter what I do the presence of a record on the right of the join drops both records. The left record set is coming from a database and being cached before the join. The right is coming from CAS and is also being cached. The join key is being indexed in both caches.
    I've tried numerous things including...
    Renaming the record key property
    Renaming the property I'm trying to add (both source and target)
    Using a different CAS adapter (delimiter and native xml)
    Checked casing of EVERYTHING.
    I'm at my wit's end. Any help would be much appreciated.

    The left record is being dropped entirely?  I've not heard of that before, but it will be due to data integrity.  Try adding record adapters with direction=output and format=xml before the two separate feeds into join, and then one after the join - these will be written out to ./data/forge_output (or maybe ./data/processing), and you should hopefully be able to see something in the raw data that will explain why this is happening.  Also, check the forge and dgidx logs (./logs/forges/Forge/Forge.log and ./logs/dgidxs/Dgidx/Dgidx.log) to see if there are messages about duplicate record keys.
    Michael

  • LEFT JOIN not exactly working

    Hi all,
    Hoping you can help me with my SQL query. I want to do a
    simple LEFT JOIN between two tables...fair enough right? Yeah,
    well, it works and all rows are returned from the LEFT table even
    if there are nmo matching rows in the RIGHT table.
    BUT, when I apply a few conditions using WHERE after this
    LEFT JOIN the whole point of the LEFT JOIN seems to not work. I
    only get rows from the LEFT where they match in the RIGHT.
    For example...this following code works and returns all LEFT
    rows despite there not being a match in the RIGHT.
    <cfquery name="getSchemaFields" datasource="#request.dsn#"
    username="#request.username#" password="#request.password#">
    SELECT schema_#getSchemas.schema_token#_fields.*,
    fields_content.*
    FROM schema_#getSchemas.schema_token#_fields
    LEFT JOIN fields_content
    ON schema_#getSchemas.schema_token#_fields.field_type_uuid =
    fields_content.field_content_field_uuid
    </cfquery>
    But, what I really need is to apply some conditions on the
    rows I want from the right table based on an ID like as follows...
    <cfquery name="getSchemaFields" datasource="#request.dsn#"
    username="#request.username#" password="#request.password#">
    SELECT schema_#getSchemas.schema_token#_fields.*,
    fields_content.*
    FROM schema_#getSchemas.schema_token#_fields
    LEFT JOIN fields_content
    ON schema_#getSchemas.schema_token#_fields.field_type_uuid =
    fields_content.field_content_field_uuid
    WHERE fields_content.field_content_item_id = <cfqueryparam
    cfsqltype="cf_sql_integer" value="#getSchemas.item_id#" />
    OR fields_content.field_content_item_id = NULL
    AND fields_content.field_content_item_uuid = <cfqueryparam
    cfsqltype="cf_sql_varchar" value="#getSchemas.item_uuid#" />
    OR fields_content.field_content_item_uuid = NULL
    </cfquery>
    Now I don't get any errors but what I do get is rows from the
    left ONLY when they match rows in the RIGHT. I still need all the
    rows from the LEFT despite this. The WHERE conditions seems to stop
    this happening.
    I know it's probably blindingly simple but I just can't get
    my head around it and I'm pulling my hair out about it!
    Hope somebody can assist me in this.
    Many thanks in advance!!
    Mikey.

    > Now I don't get any errors but what I do get is rows
    from the left ONLY when
    > they match rows in the RIGHT. I still need all the rows
    from the LEFT despite
    > this. The WHERE conditions seems to stop this happening.
    You need to stop to think about how the query is being
    executed.
    FIRST the FROM recordset is created which is the result of
    the join
    statement. This will have all your "left" rows, and null-data
    for
    unmatched "right" rows.
    THEN the WHERE clause is executed, which will filter out any
    rows from the
    recordset create in the FROM recordset.
    So if yuor data is this:
    TBL_FRUIT
    FRT_ID, FRT_NAME
    1, Apple
    2, Banana
    3, Cherry
    TBL_STOCK (<sung>we have no bananas, we have no bananas
    today</sung>)
    STK_ID, FRT_ID, STK_LEVEL
    1, 1, 12
    2, 3, 100
    And if you FROM clause is this:
    from TBL_FRUIT F left outer join TBL_STOCK S on F.FRT_ID =
    S.FRT_ID
    You get a record set thus:
    1, Apple, 12
    2, Banana, null
    3, Cherry, 100
    Now if you have a WHERE filter, thus:
    WHERE S.STK_LVEL > 0
    You're going tobe filtering out the banana row, because it
    DOESN'T have a
    STK_LEVEL > 0
    1, Apple, 12
    3, Cherry, 100
    You need to get all your filtering done on the STOCK table
    *before*
    left-joining it to the FRUIT table, if you want to have all
    the fruit rows
    in the final result.
    Dan's detailed how to effect this.
    Make sense?
    Adam

  • 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

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

  • 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

  • JPQL LEFT JOIN FETCH Results in NPE when DescriptorCustomizer in Place

    I have a unidirectional one-to-many mapping between the following two entities:
    @Entity
    @Table(name="INVC_CNTRL")
    public class InvoiceControl implements Serializable {
        @Id
        @Column(name="INVC_CNTRL_ID")
        private Long invoiceControlId = null;
        @OneToMany(fetch = FetchType.LAZY)
        private List userDefineds;
    @Entity
    @Table(name="USER_DEFINED")
    public class UserDefined implements Serializable {
        @Column(name="USER_DEFINED_TABLE")
        private java.lang.String userDefinedTable;
        @Column(name="USER_DEFINED_FK")
        private long userDefinedForeignKey;
    I wrote the following DescriptorCustomizer to address a constant JoinColumn value:
            ManyToManyMapping mapping = (ManyToManyMapping) descriptor.getMappingForAttributeName("userDefineds");
            if (null != mapping) {
                String tableName = descriptor.getTableName();
                String primaryKey = descriptor.getPrimaryKeyFields().get(0).getName();
                ExpressionBuilder builder = new ExpressionBuilder(mapping.getReferenceClass());
                mapping.setSelectionCriteria(builder.getField("USER_DEFINED_FK").equal(builder.getParameter(primaryKey))
                    .and(builder.getField("USER_DEFINED_TABLE").equal(tableName)));
    This works as expected with JPQL "select a from InvoiceControl a join fetch a.userDefineds" but when I change the "join fetch" to "left join fetch", I get the following NPE:
    Caused by: java.lang.NullPointerException
         at org.eclipse.persistence.internal.expressions.SQLSelectStatement.appendFromClauseForOuterJoin(SQLSelectStatement.java:403)
         at org.eclipse.persistence.internal.expressions.SQLSelectStatement.appendFromClauseToWriter(SQLSelectStatement.java:521)
         at org.eclipse.persistence.internal.expressions.SQLSelectStatement.printSQL(SQLSelectStatement.java:1679)
         at org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.printSQLSelectStatement(DatabasePlatform.java:3178)
         at org.eclipse.persistence.platform.database.OraclePlatform.printSQLSelectStatement(OraclePlatform.java:932)
         at org.eclipse.persistence.internal.expressions.SQLSelectStatement.buildCall(SQLSelectStatement.java:782)
         at org.eclipse.persistence.internal.expressions.SQLSelectStatement.buildCall(SQLSelectStatement.java:792)
         at org.eclipse.persistence.descriptors.ClassDescriptor.buildCallFromStatement(ClassDescriptor.java:813)
         at org.eclipse.persistence.internal.queries.StatementQueryMechanism.setCallFromStatement(StatementQueryMechanism.java:390)
         at org.eclipse.persistence.internal.queries.StatementQueryMechanism.prepareSelectAllRows(StatementQueryMechanism.java:315)
         at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.prepareSelectAllRows(ExpressionQueryMechanism.java:1721)
         at org.eclipse.persistence.queries.ReadAllQuery.prepareSelectAllRows(ReadAllQuery.java:813)
         at org.eclipse.persistence.queries.ReadAllQuery.prepare(ReadAllQuery.java:744)
         at org.eclipse.persistence.queries.DatabaseQuery.checkPrepare(DatabaseQuery.java:661)
         ... 8 more
    Inspecting the 2.5.1 source, this suggests relationAlias is null.
    I've tried a number of things to no avail. If I disable the DescriptorCustomizor and instead add a @JoinColumn on the OneToMany defining half of the join, it works. Of course the result is incorrect because it's failing to discriminate by the table name.
    Is this a bug or am I making another JPA noob mistake?
    Thanks.

    I was able to get similar behaviour doing similar JPQL. I have entered a bug in TopLink Essentials. 2465.
    I did note that having the objects in memory made a significant difference (< .5 seconds for 1000 objects, each with 2 in the 1:M).

  • AIR 1.5.2 vs AIR 2.0 outer left join - column name issues

    Hi All,
    I was wondering if anyone has seen this or know a workaround to this issue.
    After a machine got updated to AIR 2.0 our apps started to fail. Upon further inspection I discovered that the column names in the return results from an SQLite query using "outer left join" were different between AIR 1.5.2 and AIR 2.0.
    Here's my proof of concept: (I attempted to make this as sort as possible but reproduce the issue)
    private function runTest():void{
                        var conn:SQLConnection = new SQLConnection();
                        var stmt:SQLStatement = new SQLStatement();
                        var res:Array = [];
                        stmt.text = "SELECT tableOne.int, tableAlias.varchar " +
                                  "from tableOne " +
                                  "outer left join (SELECT * FROM tableTwo) as tableAlias " +
                                  "on (tableOne.int == tableAlias.int)";
                        conn.open(File.applicationDirectory.resolvePath("tempdb.db"));
                        stmt.sqlConnection = conn;
                        stmt.execute();
                        conn.close();
                        res = stmt.getResult().data as Array
                        trace(ObjectUtil.toString(res));
    AIR 1.5.2 trace results:
    (Array)#0
      [0] (Object)#1
        tableAlias_varchar = "apple"
        tableOne_int = 0
      [1] (Object)#2
        tableAlias_varchar = "boat"
        tableOne_int = 1
      [2] (Object)#3
        tableAlias_varchar = "cat"
        tableOne_int = 2
    AIR 2.0 trace results:
    (Array)#0
      [0] (Object)#1
        int = 0
        varchar = "apple"
      [1] (Object)#2
        int = 1
        varchar = "boat"
      [2] (Object)#3
        int = 2
        varchar = "cat"

    I'm having an issue which I think is similar but the workaround does not work.
    Using a table like the one below:
    uid
    name
    parentuid
    1
    math
    2
    science
    3
    language arts
    4
    addition
    1
    5
    subtraction
    1
    6
    division
    1
    7
    multiplication
    1
    8
    geology
    2
    9
    physics
    2
    10
    biology
    2
    11
    phonics
    3
    12
    literature
    3
    13
    grammar
    3
    I execute the following query:
    SELECT child.uid, child.name, child.parentuid, parent.uid, parent.name, parent.parentuid
    FROM category AS parent, category AS child
    WHERE child.parentuid=parent.uid
    GROUP BY child.uid
    In AIR 1.5 I get:
    (Array)#0
      [0] (Object)#1
        child_name = "addition"
        child_parentuid = 1
        child_uid = 4
        parent_name = "math"
        parent_parentuid = (null)
        parent_uid = 1
      [1] (Object)#2
        child_name = "subtraction"
        child_parentuid = 1
        child_uid = 5
        parent_name = "math"
        parent_parentuid = (null)
        parent_uid = 1
      [2] (Object)#3
        child_name = "division"
        child_parentuid = 1
        child_uid = 6
        parent_name = "math"
        parent_parentuid = (null)
        parent_uid = 1
    But in 2.0 I get:
    (Array)#0
      [0] (Object)#1
        name = "math"
        parentuid = (null)
        uid = 1
      [1] (Object)#2
        name = "math"
        parentuid = (null)
        uid = 1
      [2] (Object)#3
        name = "math"
        parentuid = (null)
        uid = 1
    I can't think of any way to make this work in both versions.

Maybe you are looking for

  • Regarding Selection Screen field making display field  in ALV report

    Hi All,            In ALV Report,  at runtime how can i make the field as Display Field in selection screen . Thks & Regds Shailesh

  • LSMW me51n, how to create one PR document for all the records in the  file

    HI all, I need to create LSMW for t-code me51n -Create Purchase Requisition. I`m using Bapi BUS2105, method CREATEFROMDATA, idoc message type PREQCR, basic type PREQCR03. The problem is that the LSMW is creating different idoc and different PR docume

  • Profit Centers for Raw Materials

    Hi Experts, I would like to know in general which profit center will be used in raw materials. For example raw material, say sugar, it can be used in finished product A and finished product B, its like a shared service, in this case which profit cent

  • "Cannot save alias" error message

    I am trying to create an alias and the message that pops up is "Cannot save alias." What does this mean? It doesn't say that the alias is unavailable. I've been getting this error message since I migrated from MobileMe, which was over 6 months ago. I

  • Slow mass insert on base table

    I have a table with a text index. If there are mass inserts into the table (e.g. 1Mio rows), the inserts are very slow. The inserts take around 5min without index. The inserts take 2.5hours with index though sync mode is manual. the index looks like