0

I got a (guess) really simple question here. I use the query below, to get the lowest prices of some objects. I get the lowest price but the price id (pid) is not the one of the lowest price but another one.

What should i do to get the right pid too?


Table

pid, oid, price
1, 10, 300
2, 10, 400
3, 10, 500
4, 20, 310
5, 20, 410
6, 20, 510

Query

SELECT  pid, oid, min(price)
FROM prices
group by oid
Mike
  • 5,416
  • 4
  • 40
  • 73
  • *"What should i do to get the right pid too?"* -- write the correct query. `GROUP BY` cannot be used for that. Take a look at [this answer](http://stackoverflow.com/a/28090544/4265352) provided to a similar query to get an idea how to work it out. – axiac Nov 18 '16 at 15:07
  • This one got me the solution: http://stackoverflow.com/questions/7745609/sql-select-only-rows-with-max-value-on-a-column – Mike Nov 18 '16 at 15:21
  • @axiac The question was a bit unclear, hence my editing the answer several times. – Tim Biegeleisen Nov 18 '16 at 15:23

0 Answers0