troubleshooting Question

sql help  - LEFT JOIN, want to include rows that do not have a match

Avatar of mytfein
mytfein asked on
Oracle Database
30 Comments7 Solutions766 ViewsLast Modified:
Hi EE,

This is a project for work. I work for a school.

I want to pull students from ACADEMIC_STUDY,  and ADDRESS_CURRENT tables.

The ADDRESS_CURRENT table can have many different rows for ONE student, because we carry many different addresses.

MA - mailing address
BU - business address  (for staff members)
FA  - for financial aid to be sent to


So since I am pulling students, i want MA information. If the student DID NOT  provide mailing info. They would not have a MA row, but i still want to include them.

Sample data

ACADEMIC_STUDY
1111111 Washington, George
2222222 Lincoln, Abraham

ADDRESS_CURRENT
1111111  Washington, George   MA
2222222  LIncoln, Abraham        BU

results set

1111111 Washington, George  MA
2222222 Lincoln, Abraham       null


I coded IN ('MA', NULL),  but I think Oracle is handling this as an EQUI JOIN and i am not getting the unmatched records

Do I have to code the WHERE CLAUSE in a special way like with a + sign?

tx for your help, sandra

======


select ACADEMIC_STUDY.ACADEMIC_YEAR,
       ACADEMIC_STUDY.ACADEMIC_YEAR_DESC,
       ACADEMIC_STUDY.ACADEMIC_PERIOD,
       ACADEMIC_STUDY.ACADEMIC_PERIOD_DESC,
       ACADEMIC_STUDY.ID,
       ACADEMIC_STUDY.NAME,
     
       ADDRESS_CURRENT.ADDRESS_TYPE,
       

    ODSMGR.DMC_MAX_TERM_FOR_STUDENTS_PRGM(ACADEMIC_STUDY.Person_Uid,
                                             '201330',
                                             'N',
                                             ACADEMIC_STUDY.Program) as Calc_MaxTerm

  from ODSMGR.DMC_V_ACADEMIC_STUDY_WITH_ATTR     ACADEMIC_STUDY
       ,ODSMGR.ADDRESS_CURRENT                    ADDRESS_CURRENT
 

 where ACADEMIC_STUDY.ACADEMIC_PERIOD =
       ODSMGR.DMC_MAX_TERM_FOR_STUDENTS_PRGM(ACADEMIC_STUDY.Person_Uid,
                                             '201330',
                                             'N',
                                             ACADEMIC_STUDY.Program)
                                             
   and ACADEMIC_STUDY.PERSON_UID = ADDRESS_CURRENT.ENTITY_UID(+)                                                  
   AND ACADEMIC_STUDY.COLLEGE = 'MD'
   AND ACADEMIC_STUDY.STUDENT_STATUS IN ('AS', 'LA')
   
   AND ADDRESS_CURRENT.ADDRESS_TYPE IN ('MA', NULL)
 
 order by
          ACADEMIC_STUDY.ACADEMIC_PERIOD
         ,ACADEMIC_STUDY.NAME
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 7 Answers and 30 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 7 Answers and 30 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros