ไม่รู้เกี่ยวกันไหม
ใส่ HN จาก Patient -> person
select p.hn, p.fname, p.lname, p.cid, p1.cid, p1.fname, p1.lname, p1.patient_hn
from patient p
join person p1 on p1.cid=p.cid
where p1.patient_hn is null and p.cid not like "111111111%" and concat(p.fname,p.lname) = concat(p1.fname,p1.lname)
update person p1
join patient p on p.cid=p1.cid
set p1.patient_hn=p.hn
where p1.patient_hn is null and p.cid not like "111111111%" and concat(p.fname,p.lname) = concat(p1.fname,p1.lname)
update patient p inner join ptcardno c on c.hn=p.hn set p.cid=replace(c.cardno,"-","") where p.cid is null