Ok, with the DAL I solved it in the following way and did the join "manually":
# get last val_date for each prop maxdate = db.prop_val.val_date.max().with_alias('max_val_date') rows1 = db().select(db.prop_val.prop_id.with_alias('prop_id'), maxdate, groupby=db.prop_val.prop_id) # get name, price, last val_date and amount for each prop result = [] for row in rows1: query = (db.prop_val.val_date == row.max_val_date) & \ (db.prop_val.prop_id == row.prop_id) & \ (db.prop_val.prop_id == db.prop.id) rows = db(query).select(db.prop.name.with_alias('name'), db.prop.price.with_alias('price'), db.prop_val.val_date.with_alias('val_date'), db.prop_val.amount.with_alias('amount')) result.extend(rows) But I think this method will become cumbersome if the analysis is a little bit more complicated and more aggregates have to be joined together. stex -- 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.