Say I have a query like so:
subquery = select(table1.c.id,
table1.c.type,
table1.c.some_category,
table2.c.some_other_category).join(table2,
table1.c.id== table2.c.id)
I want to use this query to perform another join on a third table. Like so:
# Fetch data
another_query = session.query(table3.c.id,
table3.c.aa,
table3.c.bb,
table3.c.cc,
table3.c.dd).subquery()
join = select(another_query.c.id,
another_query.c.aa).join(subquery,
another_query.c.id== subquery.c.id)
result = session.execute(join).fetchmany(1000)
I get the following error: Join target, typically a FROM expression, or ORM relationship attribute expected, got <sqlalchemy.sql.selectable.Select object.
How can I reuse the mentioned select subquery in the join statement?