SELECT person.pid,
CONCAT(ctitle.titlename,person.fname,' ',person.lname) AS ' ชื่อ-สกุล',person.idcard,person.typelive,
house.hno,right(house.villcode,2) AS moo,
person.nation,person.origin,person.intercode
FROM person
Inner Join house ON person.pcucodeperson = house.pcucode AND person.hcode = house.hcode
LEFT JOIN ctitle ON person.prename = ctitle.titlecode
LEFT JOIN persondeath ON person.pid = persondeath.pid AND person.pcucodeperson = persondeath.pcucodeperson
where
Right(11-((Left(person.idcard,1)*13)
+(Mid(person.idcard,2,1)*12)
+(Mid(person.idcard,3,1)*11)
+(Mid(person.idcard,4,1)*10)
+(Mid(person.idcard,5,1)*9)
+(Mid(person.idcard,6,1)*8)
+(Mid(person.idcard,7,1)*7)
+(Mid(person.idcard,8,1)*6)
+(Mid(person.idcard,9,1)*5)
+(Mid(person.idcard,10,1)*4)
+(Mid(person.idcard,11,1)*3)
+(Mid(person.idcard,12,1)*2)) Mod 11,1) <> Right(person.idcard,1)
AND persondeath.pid IS NULL
ORDER BY person.pid ASC;