Works but results in two queries. A standard query would be:

SELECT date, min(value) as value from data_table

I'm doing the query across millions of rows so I'm sensitive to
performance.

On Feb 16, 3:41 pm, Jeremy Evans <[email protected]> wrote:
> On Feb 16, 2:36 pm, Jason Thomas <[email protected]> wrote:
>
> > Is there an easy way to return additional columns when finding the min
> > or max in a particular column?
>
> > For example:
> > data_table:
> > | date  | value |
> > | 2011 | 10
> > | 2010 | 5
>
> > DB[:data_table].min(:value) => 5
>
> > I also want to see 2010 in the result as well.
>
> Then you don't just want the minimum value, which is what #min
> returns.  My guess is you want all rows where value equals the minimum
> value:
>
>   DB[:data_table].filter(:value=>DB[:data_table].min(:value)).all
>
> Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to