-4

I have 2 columns called price and PID in database called seatinginfo. Both columns will have multiple of the same values like

pid 1,1,1,1,2,2,2,2,2,2,2,3,3,3,3,3
price 10,10,30,40,60,80,70,90,90,90,90 etc

I'm looking to make a query that will give me a list of all unique prices and pick just 1 or the max connected pid. So example I only want one price,pid like 10,1 30,1 40,1 60,2 etc

Thanks

Dale K
  • 25,246
  • 15
  • 42
  • 71
kivi12k
  • 13
  • 5
  • I can do select price,PID from seatinginfo group by price,PID but it won’t give me unique price. Will only give me where price and PID combined are unique. I want unique price and idc which PID it gives me as long as it matches any of the price – kivi12k Apr 06 '22 at 20:49
  • rows are not columns, probably you are asking for [this](https://stackoverflow.com/questions/6841605/get-top-1-row-of-each-group) – Stu Apr 06 '22 at 20:53
  • Ya my bad. I am looking for a list of rows where just price is unique and it can return any of the matching PID. – kivi12k Apr 06 '22 at 20:59
  • You haven't shown anything where there's any sort of relationship between `PID` and `PRICE`. Highly suggest posting a minimally reproduceable sample. – Edward Radcliffe Apr 06 '22 at 21:14
  • Are you really still using sql 2008? It has been unsupported for several years now. Time to upgrade to something modern. – Sean Lange Apr 06 '22 at 21:19
  • A lot of legacy code and running on many servers. Too much of a headache to upgrade – kivi12k Apr 06 '22 at 21:23
  • Sql server is backwards compatible. Any code that is running today will continue to work in the new version. But that is up to you. It is like you are still running win98 because upgrading is too much hassle. – Sean Lange Apr 07 '22 at 12:37

1 Answers1

3

This is probably as simple as basic aggregation. Something like this should work based on the pretty vague details.

select price
    , max(pid)
from YourTable
group by price
Sean Lange
  • 33,028
  • 3
  • 25
  • 40