I have a table called order
which contains columns id
, user_id
, price
. I would like to select each user's most expensive order - the order for which that user paid the highest price. I want to select order.user_id
and order.price
in the same query.
views:
17answers:
2This one doesn't work right. Let me try the second one.
Omer Hassan
2010-08-27 12:58:50
No, I'm sorry it does work correctly but there's something else I needed too.
Omer Hassan
2010-08-27 12:59:50
A:
SELECT order.user_id, A.price
FROM `order`
LEFT JOIN
(SELECT user_id, price FROM `order` ORDER BY price DESC) A USING (user_id)
Sjoerd
2010-08-26 07:38:01