After much trial and re-re-..-reading the book, I came to this solution: acc = db.account(nb=2110) # to find the account stats = db((db.statement.debit==acc.id) | (db.statement.credit==acc.id) ).select() # to find the statements
Best regards On Sep 30, 9:10 am, arutti <andre.ru...@gmail.com> wrote: > Hello, > > I'm trying to make this simple query > > SELECT a.*, s.* FROM account a, statement s WHERE a.nb = '2110' AND > (a.id = s.debit OR a.id = s.credit) > > with query, set, rows objects > > the tables are defined as follow: > ..... > db.define_table('account', > Field('id','id', > represent=lambda id:SPAN(id,' > ',A('view',_href=URL('read',args=id)))), > Field('nb', 'integer', required=True, unique=True), > Field('typ', 'string'), > Field('name', 'string', required=True, unique=True), > format='%(nb)s %(typ)s %(name)s' > ) > db.account.typ.requires=IS_IN_SET(('Actif', 'Passif', 'Charge', > 'Recette')) > > db.define_table('statement', > Field('id','id', > represent=lambda id:SPAN(id,' > ',A('view',_href=URL('read',args=id)))), > Field('date', 'date', required=True, notnull=True), > Field('debit', type='reference account'), > Field('credit', type='reference account'), > Field('amount', 'double', required=True, notnull=True), > Field('desc', 'string', required=True, notnull=True) > ) > ..... > > Best regards