ตัวนี้อีก เลือกเอา น่ะครับ แล้วแต่ จะ Apply
select h.village_id,h.address,p.* ,pc.name as pttype_name,x.name as sex_name ,n.name as nationality_name,
concat(p2.fname,' ',p2.lname) as father_name , concat(p3.fname,' ',p3.lname) as mother_name ,
concat(p4.fname,' ',p4.lname) as couple_name , e.name as education_name ,
o.name as occupation_name,r.name as religion_name , y.name as marrystatus_name ,t.house_regist_type_name ,
f.family_no , pp.person_house_position_name from person p
left outer join house h on h.house_id = p.house_id
left outer join pttype pc on pc.pttype = p.pttype
left outer join sex x on x.code = p.sex
left outer join nationality n on n.nationality = p.nationality
left outer join education e on e.education = p.education
left outer join occupation o on o.occupation = p.occupation
left outer join religion r on r.religion = p.religion
left outer join marrystatus y on y.code = p.marrystatus
left outer join person p2 on p2.person_id = p.father_person_id
left outer join person p3 on p3.person_id = p.mother_person_id
left outer join person p4 on p4.person_id = p.couple_person_id
left outer join person_house_position pp on pp.person_house_position_id = p.person_house_position_id
left outer join family f on f.family_id = p.family_id
left outer join house_regist_type t on t.house_regist_type_id = p.house_regist_type_id
where p.death = 'N' and
p.age_y between 0 and 6 and h.house_id <> 1
order by round(h.address),p.person_id desc