On 14 July 2010 16:44, Max Williams <[email protected]> wrote:
> Rob Nichols wrote:
>> I think this SQL would do it:
>>
>> SELECT *
>> FROM `states`
>> WHERE created_at < '2010-04-16'
>>   OR created_at = (
>>     SELECT created_at
>>     FROM `states`
>>     ORDER BY created_at ASC
>>     LIMIT 1)
>> ORDER BY created_at DESC
>> LIMIT 1
>>
>> But your original solution would be easier to maintain!
>
> Thanks rob. It didn't occur to me that my fallback option will always
> just be the one with the lowest created_at, rather than the one after a
> given time (since we already established that there aren't any before
> the time with the first option).

Is there any advantage to this rather than the original solution (now
simplified by the realisation that the second query does not need the
:conditions spec)?  It is all done in one query, but both parts of the
query will be executed even when the second part is not required, I
think.

Colin

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: 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/rubyonrails-talk?hl=en.

Reply via email to