SELECT visit.visitdate
,CONCAT(ctitle.titlename,person.fname,' ',person.lname) AS 'ชื่อ'
,visitdiag.diagcode
,visitdiag.doctordiag
,`user`.fullname
FROM visitdiag
LEFT JOIN visit ON visitdiag.pcucode=visit.pcucode and visitdiag.visitno=visit.visitno
LEFT JOIN person ON visit.pcucodeperson=person.pcucodeperson AND visit.pid=person.pid
LEFT JOIN ctitle ON person.prename = ctitle.titlecode
LEFT JOIN `user` ON visitdiag.doctordiag=`user`.username
WHERE diagcode LIKE 'a%'
AND diagcode NOT LIKE 'a69%'
AND visit.visitdate BETWEEN '2014-10-01' AND '2015-09-30'
ORDER BY visitdate;