This I want to do: 1) I want to find all names that satisfy this query column_names = session.query(tab.c.name).filter(tab.c.value==354)
2) Among those rows I want to find those with the highest id ( all rows with the same name are fist grouped and only the one with the highest id is retained the rest is discarded). Each of the names satisfying the query 1 will be represented with one row having the highest id: column_names = [column_name for (column_name,) in column_names] query=sess.query(func.max(tab.c.id),tab.c.name).group_by(*column_names).all() Is there any better way to do this? Thanks -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.