I don't think UNION Is yet supported. Someone suggested: r1=db((db.document.person==db.person.id) & (db.person.company == company_id)).select(db.document.ALL,orderby=db.document.name)
r2=db(db.document.company == company_id).select(orderby=db.document.name) docs=r1|r2