SELECT
p.pid,
CONCAT(c.titlename,p.fname,' ',p.lname) AS 'ชื่อ-สกุล',
getAgeYearNum (birth,CURDATE()) AS 'อายุ',
co.occupaname AS 'อาชีพ',
p.marystatus AS 'สถานภาพสมรส'
FROM
person AS p
INNER JOIN ctitle AS c ON p.prename = c.titlecode
INNER JOIN coccupa AS co ON p.occupa = co.occupacode
WHERE
getAgeYearNum (birth,CURDATE()) < '12' 
AND p.pid NOT IN ((SELECT persondeath.pid FROM persondeath)) AND
p.occupa NOT IN (902, 9002, 9000,015)
ORDER BY getAgeYearNum (birth,CURDATE())