select dm.hn,p.pname,p.fname,p.lname,dm.lastdate
from (select o.hn,max(o.vstdate) lastdate
from ovstdiag o
where o.icd10 between 'E10' and 'E1499'
group by o.hn) dm
left join (select o.hn
from ovstdiag o
where o.icd10 between 'I10' and 'I1599'
group by o.hn) ht on dm.hn=ht.hn
left join patient p on dm.hn=p.hn
where ht.hn is null