SELECT p.idcard cid,ctitle.titlename pname,p.fname,p.lname,p.birth,p.sex,house.hno address,village.villno moo,
left(house.villcode,6)aid,v.visitdate screen_date,'Y' screen_status,'Y' screen_right,'Y' screen_left
FROM visit v
INNER JOIN visitdiag vd ON vd.pcucode = v.pcucode AND vd.visitno = v.visitno
INNER JOIN person p ON v.pcucodeperson = p.pcucodeperson AND v.pid = p.pid
left join ctitle on p.prename = ctitle.titlecode
inner join house on p.hcode = house.hcode and p.pcucodeperson = house.pcucode
inner join village on house.villcode = village.villcode and house.pcucode = village.pcucode
where vd.diagcode = 'H54.3'
and v.visitdate BETWEEN '2014-10-01' and '2015-09-30'; ‪#