Answer the question
In order to leave comments, you need to log in
How to select records with the maximum field value for a grouped parameter?
Two tables:
orders (заказы)
id
s (статусы заказов)
id | time | status | order_id
select max(os.time), os.orders
from order_statuses os
join orders o on os.orders = o.id
where os.status = 'NEW'
group by os.orders;
Answer the question
In order to leave comments, you need to log in
SELECT order_id
FROM order_statuses o
WHERE (status = 'new')
AND time = ( SELECT MAX(time)
FROM order_statuses m
WHERE (m.order_id = o.order_id))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question