I believe what you want is: q = session.query(Option, func.count()) q = q.outerjoin((option_senators, option_senators.c.option_id == Option.id)) q = q.group_by(Option.id) q = q.order_by(Option.name)
which will generate this SQL: SELECT [...], count(*) AS count_1 FROM options LEFT OUTER JOIN option_senators ON option_senators.option_id = options.id GROUP BY options.id ORDER BY options.name Note that query method (such as outerjoin and order_by) do not modify the query: they return a modified copy. -Conor --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---
