That's great.

There will not be so many records, so first() should work in this case but 
i really appreciate the added insight, that is really useful to know. 

Thank you.


On Saturday, January 2, 2016 at 2:43:59 PM UTC-8, Niphlod wrote:
>
> I second this BUT I still want to point out that .first() is a great tool 
> but it works at python level. In a "people" table holding 8M results, 
> you'll wait a lot. Use - WHENEVER and WHEREVER possible - orderby.
>
> db(db.people.city == 'London').select(orderby=db.people.age, 
> limitby=(0,1)).first()
>
> will land you the youngest of London. If several people are the same 
> "youth" there's an "having" method (but it requires a "groupby", which 
> seems to counteract the "complete record in the first query" requirement ). 
> The DBA in me would suggest a crafted executesql query involving WINDOWING 
> functions (that are the only ones giving the resultset in a single query) 
> but I guess you're not that into database internals.
>
> I'd go for 2 queries or a subselect then
>
> db(
>     (db.people.city == 'London') &
>     (db.people.age.belongs(
>     db(db.people.city == 'London')._select(db.people.age.min())
> )).select()
> ).select(orderby=db.people.age, limitby=(0,1))
>
> On Saturday, January 2, 2016 at 3:41:49 PM UTC+1, DenesL wrote:
>>
>> You could do
>>
>> db(db.people.city == "London").select(orderby=db.people.age).first()
>>
>>
>>
>>
>>
>> On Saturday, January 2, 2016 at 8:12:31 AM UTC-5, UG wrote:
>>>
>>> Hi,
>>>
>>> If i have the following table 
>>> ID
>>> fist_name
>>> last_name
>>> city
>>> age
>>>
>>>
>>> I use the MIN to find the lowest age
>>>
>>> youngest = db(db.people.city == 
>>> "London").select(db.people.age.min()).first()
>>>
>>> This will only give me the lowest age in the city. Is there a way to get 
>>> the complete record in the first query without having to resort to a second 
>>> query like 
>>>
>>> result = db(db.people.age == youngest & db.people.city == 
>>> "London").select()
>>>
>>> Thanks
>>>
>>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to