SELECT
p.pid,
CONCAT(c.titlename,p.fname,' ',p.lname) AS 'ชื่อ-สกุล',
getAgeYearNum (birth,CURDATE()) AS 'อายุ',
p.birth,
p.hnomoi AS 'บ้านเลขที่',
p.mumoi AS 'หมู่ที่',
p.idcard
FROM
person AS p
INNER JOIN ctitle AS c ON p.prename = c.titlecode
INNER JOIN coccupa AS co ON p.occupa = co.occupacode
INNER JOIN persontype AS pt ON p.pid=pt.pid AND p.pcucodeperson=pt.pcucodeperson
WHERE p.pid NOT IN ((SELECT persondeath.pid FROM persondeath))
AND pt.typecode='09'
ORDER BY mumoi;