select r1.name as HN,r1.name1 as Pt_Name,r1.name2 as Pt_Age,r1.name3 as FullAddress,r1.name4 as Sex,r1.date1 as BirthDay,
r2.name as Occupation,r2.name1 as MarryStatus,r2.name2 as Nationality,r2.name3 as Citizenship,r2.name4 as Religion,
r3.name as BloodGroup,r3.name1 as DrugAllergy,r3.name2 as HomeTel,r3.name3 as InformName,r3.name4 as InformAddr,
r4.name as InformRelation,r4.name1 as Father,r4.name2 as Mother,r4.name3 as SPSName,r4.name4 as CardName,
r5.name as CardCODE,r5.name1 as PtRight,r5.name2 as PtRightCode,r5.date1 as RightExpire,
pt.email ,pt.pttype ,pt.cid as patient_pid,k.loginname ,o.name as staff_name,pi.image
from tempreport r1
left outer join tempreport r2 on r2.reportname=r1.reportname and r2.id=r1.id and r2.num=2
left outer join tempreport r3 on r3.reportname=r1.reportname and r3.id=r1.id and r3.num=3
left outer join tempreport r4 on r4.reportname=r1.reportname and r4.id=r1.id and r4.num=4
left outer join tempreport r5 on r5.reportname=r1.reportname and r5.id=r1.id and r5.num=5
left outer join patient pt on pt.hn = r1.name
left outer join patient_image pi on pi.hn=r1.name
left outer join ksklog k on k.tablename='Patient' and k.detail = r1.name
left outer join opduser o on o.loginname = k.loginname
where
r1.id="ID-{9E8CD75E-B4F4-48E7-9A90-58494213DD37}" and
r2.id="ID-{9E8CD75E-B4F4-48E7-9A90-58494213DD37}" and
r3.id="ID-{9E8CD75E-B4F4-48E7-9A90-58494213DD37}" and
r4.id="ID-{9E8CD75E-B4F4-48E7-9A90-58494213DD37}" and
r5.id="ID-{9E8CD75E-B4F4-48E7-9A90-58494213DD37}" and
r1.reportname="RB1T02" and r1.num=1
and o.loginname in ("stat","stat1","stat2")
and k.loginname in ("stat","stat1","stat2")
order by k.ksklog_id desc limit 1
ประมาณนี้อ่ะครับ...สำหรับ OPD CARD [RB1T02]