On Behalf Of Erik Boling: # you mean like the avarage of all the items together from each # vendor, if so... ah, i was imagining things :) am sorry, i thought each row stands for one item only; meaning, an item can have many prices (thru history) from a vendor. i assume vendors has many products and vice versa, and products can have many prices. In your case, i think you only get the latest single price on each vendor, so something like Product1 Vendor1 -> Price Vendor2 -> Price Product2 Vendor1 ->Price Vendor2 ->Price Vendor3 ->Price .... this is easy on database, but let's use a hash just to illustrate, C:\family\ruby>cat -n test.rb 1 # assume our dbpricing hash is our database 2 dbpricing = 3 { 4 "product1" => 5 {"vendor1" => 110, 6 "vendor2" => 100, 7 "vendor3" => 105, 8 }, 9 "product2" => 10 {"vendor1" => 115, 11 "vendor2" => 110, 12 "vendor3" => 105, 13 "vendor4" => 105, 14 }, 15 "product3" => 16 {"vendor1" => 90, 17 "vendor2" => 110, 18 }, 19 } 20 21 # let's print our small db 22 # ppv stands for pricing per vendor 23 # for each product, we print our favored price and vendor 24 dbpricing.each do |product, ppv| 25 puts "Product: #{product}" 26 least_price = 1.0/0 27 least_price_vendor = "" 28 ppv.each do |vendor,price| 29 puts " #{vendor}: #{price}" 30 if price < least_price 31 least_price = price 32 least_price_vendor = vendor 33 end 34 end 35 puts " --------------" 36 puts " Winner: #{least_price_vendor} w #{least_price}" 37 end now let's test C:\family\ruby>ruby test.rb Product: product1 vendor3: 105 vendor1: 110 vendor2: 100 -------------- Winner: vendor2 w 100 Product: product2 vendor3: 105 vendor4: 105 vendor1: 115 vendor2: 110 -------------- Winner: vendor3 w 105 Product: product3 vendor1: 90 vendor2: 110 -------------- Winner: vendor1 w 90 note, that we did not cater for ties and the vendors are not sort, so those are left as an exercise :) kind regards -botp