select p.*,a.*,concat(p.pname," ",p.fname," ",p.lname)as fullname,d.name as fulldoctor,w.name as fullward,ip.bedno,sp.name,an.* from ipt a
left join patient p on a.hn=p.hn
left outer join iptadm ip on ip.an=a.an
left join doctor d on d.code=a.admdoctor
left join ward w on w.ward=a.ward
left join an_stat an on an.an=a.an
left outer join spclty sp on sp.spclty=an.spclty
where a.an="510004157"