SELECT
person.pid,
person.idcard,
person.prename,
person.fname,
person.lname,
person.birth,
house.hno,
person.nation,
visit.visitno,
visit.visitdate,
right(house.villcode,2) AS moo
FROM
person
Inner Join house ON person.pcucodeperson = house.pcucode AND person.hcode = house.hcode
INNER JOIN visit ON person.pid=visit.pid
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)
ORDER BY person.pid;