Reputation: 53
I am trying to make a query to get some results:
I have a table with some data:
client | price
1 | 100
1 | 150
1 | 200
2 | 90
2 | 130
2 | 200
3 | 95
3 | 120
3 | 250
I would like with one query to select the results and order it by price and client and get them in this form, ordered by the best price of each clint:
2 | 90
2 | 130
2 | 200
3 | 95
3 | 120
3 | 250
1 | 100
1 | 150
1 | 200
Upvotes: 2
Views: 155
Reputation: 14618
SELECT tbl.client, ytbl.price
FROM (SELECT client, min(price) as mpr FROM yourtable group by client) tbl
JOIN yourtable ytbl ON ytbl.client=tbl.client
ORDER BY tbl.mpr ASC, tbl.client ASC, ytbl.price ASC
Something like that...
Upvotes: 3