ken

select c.whenclass, c.readcode, r.term, c.note, c.dateonset, c.highlight, c.classstatus, c.confidential, 'M' as ctype from classification c
inner join readv2 r on c.readcode = r.readcode
where c.patientid = '1' and c.rowinactive = 0
and c.whenclass = (select max(c2.whenclass) from classification c2 where c2.patientid = '1' and c.readcode = c2.readcode and c2.rowinactive = 0)