I am facing problem while running the below query. It takes longer time for short month duration and time out for longer duration.
SELECT DISTINCT rcs.ID,
rcs.UniqueID,
rcs.ReferanceNo,
rcs.OrderDateActual,
rcs.DelivaredToCus,
rcs.PacketNumber,
rcs.PackingCharge,
rcs.TransportCharge,
rcs.OtherAdjustment,
SUM(rcsd.TotalPrice) AS TotalPrice
FROM regular_challan_sales rcs
LEFT JOIN regular_challan_sales_details rcsd ON rcsd.UniqueID = rcs.UniqueID
WHERE rcs.OrderDateActual >= '2013-12-01'
AND rcs.OrderDateActual <= '2014-05-01'
GROUP BY rcs.UniqueID
ORDER BY rcs.OrderDateActual ASC
I need a quick solution please.