You could create a view of the table "Situation" which groups by id_person and returns max(id_status). Then you can do a normal join using the view to establish the relationship between the other two tables.
You can have a view in web2py by creating the table as normal, but marking it as migrate=False. Then create the view in the database manually to match its definition in web2py and you're set. -- Joe B. On Monday, April 28, 2014 12:30:50 PM UTC-7, Fernando Vieira wrote: > > Guys, I have a problem and can not solve, I'll describe it below > > I have three tables > > ##Person## ##Status## > ##Situation## > --name-- --id-- --id-- --status-- > --id_person-- --id_status-- > fernando 1 1 INICIADO > 1 1 > ricardo 2 2 ADAMENTO > 1 2 > evandro 3 3 OK > 1 3 > manolo 4 4 CANCELADO > 2 1 > > 2 4 > > I need to show the person's name and the last situation, using DAL > >> fernando ----- OK > >> ricardo ------- CANCELADO > >> evandro ------ null > >> manolo ------- null > > ------------------------------------------------------------------------------- > with got the query, but id_situation field comes with the first record, > and not the last > > db(db.person).select(db.person.name, db.situation.id_status, > left=db.situation.on((db.person.id > <http://db.emprestimo.id/>==db.situation.id_person), > distinct=db.person.name) > > I figured out how to bring the last record >> db(db.situation.id_person == > db.person.id <http://db.emprestimo.id/> > ).select().as_list()[-1]['id_status'] > > Perhaps by combining the queries I would have the result, but I can not > > ------------------------------------------------------------------------------ > > If anyone can help me, I'll be grateful > -- 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.