elplatt elplatt - 1 year ago 152
MySQL Question

SQLAlchemy expression language: how to join table with subquery?

I have a subquery table

, which I want to join with a table
. But
gives the following error:

Neither 'Label' object nor 'Comparator' object has an attribute 'c'

Here is my code. What am I doing wrong?

inner_stmt = select([
func.min(ratings.c.timestamp).label('mintime')]) \

stmt = select([
func.max(revisions.c.length_bytes)]) \
revisions.c.article_name == inner_stmt.c.article_name)) \

Answer Source

You are labeling your subquery inner_stmt. label is for columns or expressions, i.e. SELECT ... AS .... You want alias instead, which is for subquery expressions, i.e. FROM ... AS .... You cannot access columns (.c.<name>) from the former, even in SQL, because it's a SQL expression.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download