select "INREGION" as inregion,
concat(v.age_y,"ปี",v.age_m,"เดือน",v.age_d,"วัน") as fullage,
pt.hn as _hn_,ov.vsttime as _vsttime_,
ov.pttypeno as _PTTYPE_NO_,
ov.* ,pt.*,
concat(pt.pname,pt.fname," ",pt.lname) as fullname,
pty.name as pttypename,
t1.name as chwname,t2.name as ampname,
t3.name as tmbname,
concat(pt.addrpart," ËÁÙè ",pt.moopart," µ.",t3.name," Í.",t2.name," ¨.",t1.name) as fulladdressname,
pcn.cardno as cid,
scn.*,sp.name as spname,
ph.*,
kp.department,
from ovst ov
left outer join vn_stat v on v.vn = ov.vn
left outer join patient pt on pt.hn=ov.hn
left outer join pttype pty on pty.pttype=ov.pttype
left outer join thaiaddress t1 on t1.chwpart=pt.chwpart and
t1.amppart="00" and t1.tmbpart="00"
left outer join thaiaddress t2 on t2.chwpart=pt.chwpart and
t2.amppart=pt.amppart and t2.tmbpart="00"
left outer join thaiaddress t3 on t3.chwpart=pt.chwpart and
t3.amppart=pt.amppart and t3.tmbpart=pt.tmbpart
left outer join ptcardno pcn on pcn.hn=ov.hn
left outer join opdscreen scn on scn.vn=ov.vn
left outer join spclty sp on sp.spclty=ov.spclty
left outer join kskdepartment kp on kp.depcode=ov.main_dep
left outer join pttypehistory ph on ph.hn=ov.hn and ph.pttype=ov.pttype
where ov.vn="521209073854"
order by expiredate desc
limit 1
ประมาณนี้หรือปล่าวครับ