I have the following mysql query to fetch total amount and tax amount for each bill.
SELECT b.bill_no
, b.total_amount
, b.created_at
, b.id
, ( SELECT sum(gst_amt)
FROM bill_contents_pharmacy bc
WHERE bc.bill_id = b.id) as tgst
FROM bills b
WHERE b.bill_type = 'pharmacy'
AND cast(b.cr_at as date) >= '2017-08-01'
AND cast(b.cr_at as date) <= '2017-08-23'
AND b.is_cancelled = 0
AND b.is_deleted = 0
ORDER
BY b.bill_no ASC
This query is taking around 10 minutes inside my php code, but when I run it in phpmyadmin it's done in just 3.6 seconds. What am I doing wrong?