fetching minimum/maximum any organisation activerecord


this an age-old doubt where given list attributes 'type', 'variety' 'price', fetch record smallest cost any form there is.



in sql, by:



select f.type, f.variety, f.price   
from ( name type, min(price) minprice list organisation form ) x
inner join list f f.type = x.type f.price = x.minprice;`


we maybe embrace by:



minprices = table.minimum(:price, :group => type)  
result = []
minprices.each_pair |t, p|
outcome << table.find(:first, :conditions => ["type = ? cost = ?", t, p])
end


is there improved doing this?



Comments

Popular posts from this blog

list macos calm editors formula editors

how hibernate @any-related annotations?

why does floated <input> control floated component slip over too distant right ie7, nonetheless firefox?