[web2py] Re: Selecting records that are not referenced by other records.

2013-09-25 Thread step
Got it now. In fact, I think this example is more meaningful than the one currently in the book to illustrate why one would want to nest select into belongs. Thanks. On Wednesday, September 25, 2013 8:29:53 AM UTC+2, Niphlod wrote: > > it's explained pretty well on the book > > > http://web2py.c

[web2py] Re: Selecting records that are not referenced by other records.

2013-09-25 Thread Michael Hall
Hey guys this works a treat and I have learned something new. Thanks for the help. On Tuesday, 24 September 2013 11:16:52 UTC+1, Michael Hall wrote: > > I am not the most awesome SQL person and as such I am having trouble > constructing a query I need. > > I have two tables in a database called

[web2py] Re: Selecting records that are not referenced by other records.

2013-09-25 Thread onetwomany
Hahah... I hope that was not meant as a perjorative!! But no... more like a postgresql novice myself.. Anyway, it's hard to see how the two query plans are equivalent... don't have time to work though the example but would be interested to see the comparison if someone tries it. On Wednesday,

[web2py] Re: Selecting records that are not referenced by other records.

2013-09-24 Thread Niphlod
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 computationa

[web2py] Re: Selecting records that are not referenced by other records.

2013-09-24 Thread onetwomany
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 r

[web2py] Re: Selecting records that are not referenced by other records.

2013-09-24 Thread Niphlod
it's explained pretty well on the book http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#belongs let me know if something is not clear Il giorno mercoledì 25 settembre 2013 07:11:27 UTC+2, step ha scritto: > > Niphlod, can you please explain why you're using method _se

[web2py] Re: Selecting records that are not referenced by other records.

2013-09-24 Thread step
Niphlod, can you please explain why you're using method _select instead of select in your code below? In there no need to connect to SQL to set all_courses? On Tuesday, September 24, 2013 3:35:34 PM UTC+2, Niphlod wrote: > > you can do that with > > all_courses = db(db.courses.id>0)._select(db.c

[web2py] Re: Selecting records that are not referenced by other records.

2013-09-24 Thread Niphlod
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)) you can eventually throw in a distinct on db.courses.memberid if the number of courses rows is plenty. Il giorno martedì 24 settembre 2013 12: