Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Outer join with BETWEEN clause

AceNoviceDec 27 2012 — edited Jan 14 2013
Hi All,

I have 2 tables (A and B) which i need to join. I need all records from table A and matching records from the table B. below is the structure.

TABLE A (total rows = 10)
------------
ROW_WID
GL_DATE
LOCATION_CODE

TABLE B (total = 7)
-----------
ROW_WID
START_DATE
END_DATE
LOCATION_CODE


Initially, we were asked to join based on location_code. In the table B, some of the LOCATION_CODE are missing, which is present in table A.

We wrote below query

SELECT A.*, B.START_DATE, B.END_DATE
FROM A, B
WHERE A.LOCATION_CODE = B.LOCATION_CODE (+)

This gives 10 records, where 3 records have START_DATE and END_DATE NULL. because of outer join

It gave all records from the A table. It worked fine. Now i need to add one more condition where A.GL_DATE between B.START_DATE and B.END_DATE

If i write this

SELECT A.*, B.START_DATE, B.END_DATE
FROM A, B
WHERE A.LOCATION_CODE = B.LOCATION_CODE (+)
AND A.GL_DATE BETWEEN B.START_DATE and B.END_DATE

This gives me only 7 records. IS IT POSSIBLE TO ADD OUTER JOIN with BETWEEN clause.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 11 2013
Added on Dec 27 2012
5 comments
8,716 views