views:

35

answers:

1

Hi, I am trying to make a query to get some results:

I have a table with sote 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

Thanks in advice,

Cheers nik

+3  A: 
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...

Alexander
+1: Drats - beat me.
OMG Ponies
Hi Alexander, it works great!Thank you very much :-)CheersNik
Nik
Great to hear that!I see that you're new here. If you find the answer to your question, mark it as the correct answer. When you accept an answer you get points, so does the person who gives the correct answer. It's what keeps this forum going (besides altruism).
Alexander