On Apr 10, 2014, at 3:00 PM, Mauricio de Abreu Antunes 
<[email protected]> wrote:

> 
> I am not understanding the docs because they only talk about a subselect 
> inside the WHERE. What I am doing here is retrieving a MAX(field) from a 
> SELECT.
> 
> Can someone guide me to the right direction? Thanks!

the query form here is SELECT ... FROM (subquery), there are examples of 
FROM-based subqueries at these locations:

http://docs.sqlalchemy.org/en/latest/orm/tutorial.html#using-subqueries
http://docs.sqlalchemy.org/en/latest/core/tutorial.html#using-aliases

basically any selectable itself acts like a table object, and includes a .c. 
collection.   When you have an ORM query you call subquery() in order to make 
this transition.

q1 = sess.query(col1.label('x'), col2.label('y'), 
..).filter(...).group_by(...).subquery()

q2 = sess.query(q1.c.x, func.foobar(q1.c.y), ...).filter(q1.c.x 
...).group_by(q1.c.y, ...)

> There is a related problem here: 
> https://groups.google.com/forum/#!topic/sqlalchemy/LBEyRe3w-8Q

well this answer seems to just be talking about the same thing, two varieties 
of subquery, the scalar subquery and the FROM subquery.   Some updated 
discussion of the same thing is here: 
http://docs.sqlalchemy.org/en/latest/glossary.html#term-subquery

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to