My query too much time to execute for fetching data.
SELECT `app`.*, `pat`.`title`, `email_address`, `bad_debtor`, `county`, `date_of_birth`, `dentist_id`, `doctor_id`, `ethnicity`, `first_name`, `middle_name`, `last_name`, `gender`, `pat`.`mobile_phone`, `pat`.`prevent_appointment_booking`, `pat`.`use_email`, `pat`.`use_sms`, `pat`.`recall_method`, `pat`.`status`, `pat`.`pat_id`, `pat`.`active` FROM `patients` `pat` LEFT JOIN `appoiment` `app` ON `pat`.`id` = `app`.`patient_id` WHERE (date(app.start_time) > date(NOW()) - INTERVAL 7 DAY) and `app`.`state` IN ('Completed') and `app`.`patient_id` is not NULL GROUP BY `pat`.`id`
This part
WHERE (date(app.start_time) > date(NOW()) - INTERVAL 7 DAY) and `app`.`state` IN ('Completed') and `app`.`patient_id` is not NULL
the problem is in where clause which takes too much time. help me to optimize query.
Advertisement
Answer
replace app. * with the correct column you need