SELECT DISTINCT JOB.EMPLID , JOB.EMPL_RCD , JOB.EFFDT , CIA.CIA_CODE_ITA , JOB.COMPANY , JOB.ESTABID FROM PS_JOB JOB , PS_CIA_COMP_ITA CIA WHERE JOB.COMPANY = CIA.COMPANY AND (JOB.ESTABID = CIA.ESTABID OR CIA.ESTABID = ' ') AND JOB.EFFDT = ( SELECT MAX(JOB2.EFFDT) FROM PS_JOB JOB2 WHERE JOB.EMPLID=JOB2.EMPLID AND JOB2.EFFDT<=JOB.EFFDT) AND JOB.EFFSEQ = ( SELECT MAX(JOB2.EFFSEQ) FROM PS_JOB JOB2 WHERE JOB.EMPLID=JOB2.EMPLID AND JOB2.EFFDT<=JOB.EFFDT) AND CIA.EFFDT = ( SELECT MAX(CIA2.EFFDT) FROM PS_CIA_COMP_ITA CIA2 WHERE CIA2.CIA_CODE_ITA = CIA.CIA_CODE_ITA AND JOB.COMPANY = CIA2.COMPANY AND (CIA.ESTABID = CIA2.ESTABID OR CIA2.ESTABID = ' ') AND CIA2.EFF_STATUS = 'A')
|