You have to merge them in a list and sort them at the Python/web2py level. You may be able to do
dataset_three=(dataset_one+dataset_two).sort(lambda row: row['sortfilename']) assuming both tables have the same sortfiledname and have similar record structures. Try and let us know. On Jun 13, 12:01 pm, Giuseppe Luca Scrofani <[email protected]> wrote: > Hi all, it is possible to make a query to the db and sort the elements > of multiple tables by date? > > I will try to be more specific with an example, I have this > controller, the structure of the model should be evident: > > def index(): # This is the index controller > dataset_one = db().select(db.dataset_one.id, > db.dataset_one.title, orderby= ~db.dataset_one.created_on) > dataset_one = dataset_one[:2] # limits to the last two results > > dataset_two = db().select(db.dataset_two.id, > db.dataset_two.title, orderby= ~db.dataset_two.created_on) > dataset_two = dataset_two[:2] # limits to the last two results > > return dict(dataset_one=dataset_one, dataset_two=dataset_two) > > it return two dictionaries with the last 2 entry for dataset_one and > dataset_two (4 total in 2 dict). > But what I want to accomplish is to return only one dictionary with > the two most recent entry from all dataset, so if the 2 most recent > are from dataset_one the query get this results only and ignore > dataset_two... > > To be honest I dont think is possible, but I will happy to be wrong. > Sadly, I cant restructure the db... > > I hope to have made this question clear enough... My english is not very > well... > > Thanks for any help!

