SELECT
idcard AS `เลขประชาชน`,birth AS 'วดปเกิด',
concat(ctitle.titlename,person.fname,' ',person.lname,' ','(',convert(person.pid using utf8),')')as 'ชื่อ - สกุล' ,
timestampdiff(year,person.birth,date(NOW())) AS 'อายุ'
,hnomoi AS 'บ้านเลขที่' ,mumoi AS 'หมู่'
,person.typelive
FROM
person
LEFT JOIN ctitle ON person.prename = ctitle.titlecode
WHERE getAgeYearNum(person.birth,CURDATE()) BETWEEN '20' AND '50'
AND typelive like ('1' OR '3')
AND person.pid NOT IN (SELECT person.pid
FROM person INNER JOIN visitepi ON visitepi.pid = person.pid
WHERE (visitepi.vaccinecode like '%DT%') AND visitepi.dateepi BETWEEN '2009-09-03' AND '2015-09-30')
ORDER BY mumoi