I think like this you make you union search without worry about SQL injection :
results = db(db.table1.field1 == '%{0}%'.format(form.vars.search)).select(db.table1.field1.with_alias('searchfield')) | db(db.table2.field2 == '%{0}%'.format(form.vars.search)).select(db.table2.field2.with_alias('searchfield')) You may want to play with & and | depending if you want include duplicate or not... Though, I am not sure about you database design if you need to do such thing since having the name of differents user host in table name is smelling, I would rather add a column in one of the table indicating which one between the 2 persons the host is own by and combine all the records into that single "normalized" table... Richard On Tue, Feb 16, 2016 at 12:13 PM, Alfonso Serra <aleonse...@gmail.com> wrote: > > executesql always return tuples and thats ok unless you need to to hide > columns, remove elements, edit or add data and such. > To turn a tuple into a list is just result = list(result) > > To return a table web2py has many "magic" methods like SQLFORM.grid or > SQLFORM.smartgrid that will only work if you are able to construct an union > query using DAL. > > Because you are using executesql you will have to code your view or create > a custom function with web2py helpers to generate the desired html. > > Theres a chapter > <http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Combining-rows>about > combining rows but i dont know if thats what you are looking for. > > -- > Resources: > - http://web2py.com > - http://web2py.com/book (Documentation) > - http://github.com/web2py/web2py (Source code) > - https://code.google.com/p/web2py/issues/list (Report Issues) > --- > You received this message because you are subscribed to the Google Groups > "web2py-users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to web2py+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.