select v.vstdate,v.vn,v.hn,v.cid,concat(pt.pname,pt.fname) Fname,pt.Lname
,p.name pttypename
,pt.addrpart addressno,cast(v.moopart as signed) moo,t.full_name address
,odx.icd10
,group_concat(concat(d.name,' ',d.strength,'#',o.qty) separator '|') drug
from vn_stat v
left join patient pt on pt.hn=v.hn
left join ovstdiag odx on odx.vn=v.vn
left join pttype p on v.pttype=p.pttype
left join thaiaddress t on v.aid=t.addressid
left join opitemrece o on o.vn=v.vn
left join drugitems d on o.icode=d.icode
where v.vstdate between '2013-1-1' and '2013-1-31'
and odx.icd10 between 'F00' and 'F9999'
and d.name is not null
group by v.vn