I have spent hours trying to get my query to run faster so far it works on my database.
however it takes 43 seconds to return my result. basically two tables are joined and I need to only return the latest order_history_id for each order_id with an order_status of 12.
I have tried using table shortcuts ie T1 T2 etc but to keep it simple my sql query has the relevant tables names below any help greatly appreciated
SELECT oc_order.order_id, oc_order.firstname, oc_order.lastname
FROM oc_order
INNER JOIN oc_order_history ON oc_order.order_id = oc_order_history.order_id
AND oc_order_history.comment NOT LIKE ''
AND oc_order_history.order_status_id LIKE '12'
AND order_history_id = (SELECT max(order_history_id)
FROM oc_order_history i
WHERE i.order_id = oc_order.order_id)
SHOW CREATE TABLE <tablename>on each table in the query and post to the question so we can see your schema and indexes. Also runexplain <your query>and post the results.explain <my query>but it gives error code 1064