Outer Join --> Max Effdate Subquery

SELECT J.EMPLID, N.NAME
FROM PS_JOB J, PS_NAMES N
WHERE 
J.EFFDT = (SELECT MAX(J_ED.EFFDT) FROM PS_JOB J_ED
                   WHERE J.EMPLID = J_ED.EMPLID
                   AND J.EMPL_RCD = J_ED.EMPL_RCD
                   AND J_ED.EFFDT <= SYSDATE)
AND J.EFFSEQ =(SELECT MAX(J_ES.EFFSEQ) FROM PS_JOB J_ES
                              WHERE J.EMPLID = J_ES.EMPLID
                              AND J.EMPL_RCD = J_ES.EMPL_RCD
                              AND J.EFFDT = J_ES.EFFDT)
AND J.EMPLID = N.EMPLID (+)
AND (N.EFFDT IS NULL 
         OR N.EFFDT= (SELECT MAX(N_ED.EFFDT)
                                   FROM PS_NAMES N_ED
                                   WHERE N_ED.NAME_TYPE=N.NAME_TYPE
                                   AND N_ED.EMPLID = N.EMPLID
                                   AND N_ED.EFFDT <=SYSDATE))

Comments