title: SQLAlchemy ORM select multiple entities from subquery
body: <p>I need to query multiple entities, something like <code>session.query(Entity1, Entity2)</code>, only from a subquery rather than directly from the tables. The docs have something about <a href="http://docs.sqlalchemy.org/en/rel_0_8/orm/tutorial.html?highlight=window#selecting-entities-from-subqueries" rel="noreferrer">selecting one entity from a subquery</a> but I can't find how to select more than one, either in the docs or by experimentation. </p>
  
  <p>My use case is that I need to filter the tables underlying the mapped classes by a window function, which in PostgreSQL can only be done in a subquery or CTE.</p>
  
  <p>EDIT: The subquery spans a JOIN of both tables so I can't just do <code>aliased(Entity1, subquery)</code>.</p>