try this,
I assume field addr_id on table addr is foreign key references jobs_id on table jobs.Code:select jobs_id,a.addr_atyp_code,addr_street_line1 from jobs a left join addr b on a.jobs_id = b.addr_id where jobs_status = 'A' and (a.addr_atyp_code = 'MA' or b.addr_id is null) and jobs_effective_date = (select max(b.jobs_effective_date) from jobs b where b.jobs_pidm = a.jobs_pidm)
one more thing, alias 'a' duplicate in your first post.
maybe if you post table structure it would be great help




Reply With Quote