tags:

views:

17

answers:

2

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.

+1  A: 
select user_id, max(price) from `order` group by user_id
Sjoerd
This one doesn't work right. Let me try the second one.
Omer Hassan
No, I'm sorry it does work correctly but there's something else I needed too.
Omer Hassan
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