select ip.an,concat(p.pname) as p_name,p.lname,p.cid,s.name,n.name,p.birthday,ip.born_time,
concat(p.fathername,' ',p.fatherlname) as fnl,p.father_cid,concat(p.mathername,' ',p.motherlname) as mnl,
p.mother_cid,ip.birth_weight,ip.preg_no,d.name as dname,pr.ga,
l.mother_gvalue,l.mother_p1value,l.mother_p2value,l.mother_avalue,(l.mother_lvalue+pr.child_count) as living_all,
(l.mother_lvalue+pr.child_count+l.mother_avalue) as child_all,
p2.cid as mom_cid
from ipt_newborn ip
left outer join ipt i on i.an=ip.an
left outer join patient p on p.hn=i.hn
left outer join thaiaddress t on t.addressid=concat(p.chwpart,p.amppart,p.tmbpart)
left outer join sex s on s.code=p.sex
left outer join nationality n on n.nationality=p.nationality
left outer join labor l on l.an=ip.mother_an
left outer join an_stat a on a.an=ip.mother_an
left outer join patient p2 on p2.hn=a.hn
left outer join doctor d on d.code=l.labor_who
left outer join ipt_pregnancy pr on pr.an=ip.mother_an
where ip.an="510001866" #an ของคุณใช้เหมือนผมหรือเปล่าไมอย่างนั้นให้ปรับ an ให้ตรงกับของคุณแล้วรอง ทดสอบดูอีกรอบ