DBAsupport.com Forums - Powered by vBulletin
Results 1 to 3 of 3

Thread: weird SQL result

  1. #1
    Join Date
    Jun 2000
    Posts
    295
    I have master table location and detail table
    application.

    select l.location_number, count(a.application_id)
    from application a, location l
    where
    l.location_id = 102884
    and l.location_id = a.location_id(+)
    group by l.location_number
    /

    LOCATION_NUMBER COUNT(A.APPLICATION_ID)
    ------------------------------ -----------------------
    2323 0

    While if I add a condition in where clause:
    and a.posted >= to_date('27-OCT-2000 00:00:00', 'DD-MON-YYYY HH24:MI:SS')
    and a.posted <= to_date('22-NOV-2000 00:00:00', 'DD-MON-YYYY HH24:MI:SS')

    The query will be:
    select l.location_number, count(a.application_id)
    from application a, location l
    where
    l.location_id = 102884
    and l.location_id = a.location_id(+)
    and a.posted >= to_date('27-OCT-2000 00:00:00', 'DD-MON-YYYY HH24:MI:SS')
    and a.posted <= to_date('22-NOV-2000 00:00:00', 'DD-MON-YYYY HH24:MI:SS')
    group by l.location_number
    /


    I got:

    no rows selected

    How can this happen? I want to see:

    LOCATION_NUMBER COUNT(A.APPLICATION_ID)
    ------------------------------ -----------------------
    2323 0

    Note: This is just partial query which I abstract
    to ask help.

    Also, posted field is date field.

    Thanks,









  2. #2
    Join Date
    Nov 2000
    Location
    Baltimore, MD USA
    Posts
    1,339
    Cleaning up the query a little, we might notice...
    SELECT
    L.LOCATION_NUMBER,
    COUNT(*)
    FROM
    APPLICATION A,
    LOCATION L
    WHERE
    L.LOCATION_ID = 102884 AND
    A.LOCATION_ID (+)= L.LOCATION_ID AND
    A.POSTED >= TO_DATE('27-OCT-2000', 'DD-MON-YYYY') AND
    A.POSTED <= TO_DATE('22-NOV-2000', 'DD-MON-YYYY')
    GROUP BY
    L.LOCATION_NUMBER

    that while you start by outer-joining table A into the query, you then eliminate the outer-join by using straight comparisons against the POSTED field. You would need to do (+)>=.

    In Oracle, if a table is outer-joined anywhere, the outer-joined restrictictions will be performed first, then the outer-joins, then any remaining, non-outer restrictions. This is different than SQLServer. In SQLServer, this would have worked, but not in Oracle.

    Hope this helps

    - Chris

  3. #3
    Join Date
    Jun 2000
    Posts
    295
    Thanks!

    It is the problem!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width