Il giorno mercoledì 25 settembre 2013 08:46:15 UTC+2, onetwomany ha scritto:
>
>
>
> you can do that with
>>
>> all_courses = db(db.courses.id>0)._select(db.courses.memberid)
>> all_members_not_in_courses = db(~db.members.id.belongs(all_courses))
>>
>>
>>>
> Would such an approach be computationally expensive particularly if the 
> number of rows in courses is high? Perhaps the following raw SQL expression 
> would be more efficient:
>
> from gluon.dal import Expression
> all_members_not_in_courses = db((db.members.id>0)&Expression(db, 'NOT 
> EXISTS (SELECT courses.memberid FROM courses WHERE courses.memberid=
> members.id)')).select()
>


oh boy, a MSSQL user, I guess :P  .... The query plan is roughly 
equivalent. What instead would be beneficial is "inner selecting" a 
distinct set. 

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to