[web2py] Re: Self join query missing AS

2010-04-11 Thread mdipierro
yes and no. this NO thisq = db(db.keyword.keyword == 'this')._select(db.keyword.question) result = db(db.question.id.belongs(thisq)).select(db.question.ALL) but this YES thisq = [r.question for r in db(db.keyword.keyword == 'this').select(db.keyword.question)] result = db(db.question.id.belongs

[web2py] Re: Self join query missing AS

2010-04-11 Thread Paul Wray
Please disregard last question - nested select does seem to work using the same chaining technique: thisq = db(db.keyword.keyword == 'this')._select(db.keyword.question) thatq = db(db.keyword.keyword == 'that') (db.keyword.belongs(thisq))._select(db.keyword.question) result = db(db.question.id.bel

[web2py] Re: Self join query missing AS

2010-04-11 Thread mdipierro
On Apr 11, 7:40 pm, Paul Wray wrote: > Thank you Massimo > > I didnt know about the chained queries like this ie db(q1)(q2)  . > Is this feature documented in the book? yes db()() is the same as db(()&()) > I like how this allows a neat construction for n keywords: > > q = db() > for k in keyw

Re: [web2py] Re: Self join query missing AS

2010-04-11 Thread Thadeus Burgess
Sorry, try this db(db.question.id == db.keyword.id)(db.keyword.keyword == 'this')(db.keyword.keyword == 'that').select() -Thadeus On Sun, Apr 11, 2010 at 7:46 PM, Thadeus Burgess wrote: > Does the following provide the results that you are looking for? > > db(db.question.id > 0)(db.keyword

Re: [web2py] Re: Self join query missing AS

2010-04-11 Thread Thadeus Burgess
Does the following provide the results that you are looking for? db(db.question.id > 0)(db.keyword.keyword == 'this')(db.keyword.keyword == 'that').select() -Thadeus On Sat, Apr 10, 2010 at 9:36 AM, mdipierro wrote: > I would do > > db(db.question.id.belongs(db(db.keyword.keyword=='this')).

[web2py] Re: Self join query missing AS

2010-04-11 Thread Paul Wray
Thank you Massimo I didnt know about the chained queries like this ie db(q1)(q2) . Is this feature documented in the book? I like how this allows a neat construction for n keywords: q = db() for k in keywords: q = q(db.question.id.belongs(db(db.keyword.keyword = k).select(db.qkeyword.questi

[web2py] Re: Self join query missing AS

2010-04-11 Thread Paul Wray
Thank you Massimo I didnt know about the chained queries like this ie db(q1)(q2) . Is this feature documented in the book? I like how this allows a neat construction for n keywords: q = db() for k in keywords: q = q(db.question.id.belongs(db(db.keyword.keyword = k).select(db.qkeyword.questi

[web2py] Re: Self join query missing AS

2010-04-10 Thread mdipierro
I would do db(db.question.id.belongs(db(db.keyword.keyword=='this'))._select(db.keyword.question)) (db.question.id.belongs(db(db.keyword.keyword=='that'))._select(db.keyword.question)).select(db.problem.ALL) It will be faster. On Apr 10, 8:31 am, Paul Wray wrote: > Thanks for your reply > > The

[web2py] Re: Self join query missing AS

2010-04-10 Thread Paul Wray
Thanks for your reply The SQL I wish to produce is: 'SELECT question.* FROM question, keyword as k2, keyword as k1 WHERE ((k1.keyword="this") AND (k2.keyword="that") AND (k1.question=k2.question) AND (k1.question=question.id))' That is, find all questions that have both the keyword 'this' and the

[web2py] Re: Self join query missing AS

2010-04-08 Thread mdipierro
Inner joins in DAL do not support AS. Can you show an SQL example of how you would use it? Massimo On Apr 8, 10:08 pm, Paul Wray wrote: > Hello > > I'm attempting a simple self join and having trouble with the aliases. > The slightly simplified query is: > > k1 = db.qkeyword.with_alias('k1') > k