The below query is taking time to execute. does this have any rewrite possibilities?
Query;
SELECT t_product.a_productid,
t_product.a_mpactive,
t_product.a_active,
trim( substring_index(a_reference, '_',-1)) as a_reference,
t_product.a_shopid,
t_productlang.a_name,
t_deactivatedproduct.a_reason
FROM t_deactivatedproduct
inner join ( SELECT max(a_deactivatedproductid) as a_deactivatedproductid
FROM t_deactivatedproduct
GROUP by t_deactivatedproduct.a_productid
) as a on a.a_deactivatedproductid = t_deactivatedproduct.a_deactivatedproductid
INNER JOIN t_product ON t_product.a_productid = t_deactivatedproduct.a_productid
INNER JOIN t_productlang ON t_product.a_productid = t_productlang.a_productid
AND t_product.a_shopid IN( 2, 3, 5, 6, 7, 10, 8, 15, 12, 16, 17, 26, 27, 28)
WHERE t_product.a_ispublished = 1
AND ( ( t_product.a_active = 1 AND t_product.a_mpactive = 0) OR (t_product.a_active = 0 AND t_product.a_mpactive = 1)
OR ( t_product.a_active = 0 AND t_product.a_mpactive = 0 ) )
ORDER BY t_deactivatedproduct.a_deactivatedproductid DESC
limit 700
can someone please tell me where has a problem with it and how to change it?