SELECT 
 p.pid AS HN
,p.idcard
, CONCAT(ctitle.titlename,p.fname,' ',p.lname) AS `ชื่อ`
, getAgeYearNum(p.birth,'2014-10-01') AS `อายุ`
, CONCAT(p.hnomoi,'หมู่ ',p.mumoi) AS 'ที่อยู่'
,visitepi.vaccinecode AS 'วัคซีน'
,visitepi.dateepi AS 'วันที่รับวัคซีน'
FROM
person p
INNER JOIN house h ON p.pcucodeperson = h.pcucode
AND p.hcode = h.hcode
INNER JOIN ctitle ON p.prename = ctitle.titlecode
INNER JOIN visit ON visit.pid=p.pid
LEFT JOIN visitepi ON visit.visitno=visitepi.visitno
WHERE vaccinecode ='DTS4'
AND visit.visitdate BETWEEN '2014-10-01' AND '2015-09-30'