Put the correlated subquery directly in the select
clause:
select concat(p.lname,' ' , p.fname) as name,
(select count(*) from openemr_postcalendar_events as e where e.pc_pid = p.pid) as patient_appt
from patient_data as p
where p.financial_review_exp > '2019-07-01'
Note: don’t use single quotes for column aliases! They are meant for literal strings only. In MySQL, you can use backticks to quote identifiers – but better yet, use identifiers that do not require quoting, so you don’t have to worry about that.
CLICK HERE to find out more related problems solutions.