SELECT DISTINCT CONCAT( "", d.demographic_no, "" ) as 'Chart No.', CONCAT(d.last_name,', ', d.first_name) as 'Patient Name', CONCAT(date_of_birth, '-', month_of_birth, '-',year_of_birth, ' ') as 'Date of Birth', d.hin as 'H.I.N.', CONCAT(' Home: ', d.phone, ' Work: ' , d.phone2) as 'Phone Numbers' FROM demographic d, eChart e WHERE e.{source} LIKE '%{searchtext}%' AND d.patient_status = 'AC' AND d.demographic_no = e.demographicNo AND d.provider_no = IF('{provider}'='ALL', d.provider_no , '{provider}' ) ORDER BY last_name, first_name ; ( select 'SocialHistory','SocialHistory' ) UNION ( select 'FamilyHistory','FamilyHistory' ) UNION ( select 'MedicalHistory','MedicalHistory' ) UNION ( select 'OngoingConcerns','OngoingConcerns' ) UNION ( select 'Reminders','Reminders' ) UNION ( select 'Encounter','Encounter' ) ; ( select distinct provider_no, concat(last_name,',',first_name,'(',provider_no,')') as name from provider where provider_type = 'doctor' and status = 1 ) UNION ( select 'ALL', 'All providers' ) order by name ;