[web2py] Re: Left joining two queries

2011-09-03 Thread Noel Villamor
Thank you guys, I sort of zeroed in on the solution from your replies. Little by little I am learning how things are done in web2py. :) tblBalias = db.skedp.with_alias('tblBalias') desired_result = db(db.tblB.fkA == 1).select(db.tblB.name, db.tblB.data, tblBalias.data, left = tblBalias.o

[web2py] Re: Left joining two queries

2011-09-03 Thread Massimo Di Pierro
I will make a guess: b = db.tblB.with_alias('b') db(db.tblB.fkA == 1).select(db.tblB.name,b.data,left=b.on((b.fkA==db.tblA.fkA)&(db.tblA.id==1))) If you show your SQL we can make this right. You have not explained why the output is 100,'aaa','xxx' 101,'bbb','yyy' 102,'ccc',None and not 100,'aa

[web2py] Re: Left joining two queries

2011-09-03 Thread Anthony
Does this help: http://web2py.com/book/default/chapter/06#Self-Reference-and-Aliases On Saturday, September 3, 2011 5:36:12 PM UTC-4, Noel Villamor wrote: > > TABLE db.tblB > fkA, name, data > 1,100,'aaa' > 1,101,'bbb' > 1,102,'ccc' > 2,100,'xxx' > 2,101,'yyy' > > 1st query: db(db.tblB.fk

[web2py] Re: Left joining two queries

2011-09-03 Thread Noel Villamor
TABLE db.tblB fkA, name, data 1,100,'aaa' 1,101,'bbb' 1,102,'ccc' 2,100,'xxx' 2,101,'yyy' 1st query: db(db.tblB.fkA == 1).select(db.tblB.name,db.tblB.data) name,data 100,'aaa' 101,'bbb' 102,'ccc' 2nd query: db(db.tblB.fkA == 2).select(db.tblB.name,db.tblB.data) name,data 100,'xxx' 101,'yyy' Desi

[web2py] Re: Left joining two queries

2011-09-03 Thread pbreit
Wouldn't a regular query do that? Something like: rows = db((db.tblB.fkA.belongs(1,2))) & (db.tblB.fkA==db.tblA.fldA)).select()

[web2py] Re: Left joining two queries

2011-09-03 Thread Massimo Di Pierro
I do not understand. Can you make and example why actual data? On Sep 3, 3:37 am, Noel Villamor wrote: > Say I have a parent table tblA and child table tblX: > > db.define_table('tblA', >     Field(fldA')) > > db.define_table('tblB', >     Field('fkA', db.tblA), >     Field('name', 'integer'), >