MYSQL query works perfectly fine on local server with no errors.. but when used on production server, it crashes and i have to restart the server
Here is my table structure for order_table
item_id | order_id | status_id | date
-------------------------------------------
1 | 1 | 1 | 2014-01-20
2 | 1 | 2 | 2014-01-20
3 | 1 | 3 | 2014-01-20
4 | 2 | 1 | 2014-01-21
5 | 2 | 2 | 2014-01-21
6 | 3 | 1 | 2014-01-21
7 | 3 | 2 | 2014-01-21
8 | 3 | 3 | 2014-01-22
9 | 3 | 4 | 2014-01-22
10 | 3 | 5 | 2014-01-23
-------------------------------------------
i can get the latest status of order_id by using below query
SELECT item_id, order_id, status_id
FROM order_table
WHERE item_id IN (
SELECT MAX(item_id)
FROM order_table
GROUP BY order_id
)
and status_id = '5'
order by order_id
the above query works fine on local server but crashes on production server.. however when removed GROUP BY, the query is successfully executed on production server as well.. it looks like GROUP BY is creating problems
can anybody help me with an alternative way of getting same result with different approach