I tried three way to reduce it's runtime but i can't, still it takes 97.00456 seconds, if any one can please suggest me a solution.
SELECT r.id, r.first_name, r.phone, r.checkin_id, r.device_id, replace(c.`name`,' ','') as device, r.model_id,
cv.`name` as model, r.color_id, cvc.`name` as color, r.network_id, cn.`name` as network, r.problem_id, cp.`name` as problem,
#get pid by concat device detail
IFNULL(
(SELECT id
FROM product
WHERE
#if not admin
#store_id=$input_by AND
#if not admin
name=concat(replace(c.`name`,' ',''),', ',cv.`name`,' - ',cp.`name`)
ORDER BY id DESC
LIMIT 1)
,
(SELECT id
FROM product
WHERE
#if not admin
#store_id=$inout_by AND
#if not admin
name=concat(replace(c.`name`,' ',''),' , ',cv.`name`,' - ',cp.`name`)
ORDER BY id DESC
LIMIT 1)
) AS pid,
#get pid by concat device detail END
IFNULL(
(SELECT id
FROM coustomer as cus
WHERE cus.firstname=r.first_name AND cus.phone=r.phone
LIMIT 1)
,
0
) as cid,
pc.invoice_id as invoice_id,
#(SELECT count(id) FROM invoice WHERE invoice_id=IFNULL((SELECT invoice_id FROM pos_checkin WHERE checkin_id=r.checkin_id),0) LIMIT 1) AS invoice_status,
SUM(ip.amount) as paid,
r.date,
r.input_by,
r.status
FROM checkin_request as r
LEFT JOIN pos_checkin as pc on pc.checkin_id=r.checkin_id
LEFT JOIN invoice_payment as ip on ip.invoice_id=pc.invoice_id
LEFT JOIN checkin as c ON c.id=r.device_id
LEFT JOIN checkin_version as cv ON cv.id=r.model_id
LEFT JOIN checkin_version_color as cvc ON cvc.id=r.color_id
LEFT JOIN checkin_network as cn ON cn.id=r.network_id
LEFT JOIN checkin_problem as cp ON cp.id=r.problem_id
WHERE r.checkin_id IN (
SELECT crt.checkin_id
FROM checkin_request_ticket as crt
)
GROUP BY r.checkin_id
ORDER BY id DESC
LIMIT 5
i tried using left join , tried with nested query , tried with sub query but failed. Please leave a solution if anyone does.