It would probably be best for you to figure out the correct raw sql you want, then convert it to SqlAlchemy.
Postgres is the only DB I know of that offers "DISTINCT ON (columns)" -- and even that works a bit awkward. The query that you want to do isn't actually simple -- there are concerns with how to handle duplicate rows (based on the distinct field). Often people will use "GROUP BY" + "ORDER BY" along with distincts, subselects and misc database functions. If I were in your place, I would read through some DB tutorials and StackOverflow questions on how people are dealing with similar problems. That should help you learn. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.