Could some please explain if its possible to access the columns in a sub/query, so I can join on them. Here is what I am trying to do.
First lets say i start with a query like. q = session.query(Account) now, lets say i make another query i want to join to that. q1 = session.query(ContactInfo.account_id).filter(..) q2 = session.quiery(Site.account_id).filter(..) Then, i want to union those 2 queries. q3 = q1.union(q2) so, now i have a q3 that has a a bunch of account_id's, and i would like to join that to the original "q" query that is getting data from the Account table. final_query = q.join(q3, Account.id == q3.account_id) <-- No access to the column account_id.. i understand its a union, but that doesnt change anything. i also tried final_query = q.join(q3, Account.id == q3), which produced the follow error, which might be a clue. > InvalidRequestError: Could not find a FROM clause to join from. Tried > joining to SELECT anon_1.contact_info_account_id AS > anon_1_contact_info_account_id ...query string.. AS anon_1, but got: Can't > find any foreign key relationships between ... and 'FromGrouping object'. > Perhaps you meant to convert the right side to a subquery using alias()? > FYI, this is not the real query i need, I understand that the query above could just be written differently, im just using this as an example so you can understand what im trying to do. Thanks -- 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 sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/groups/opt_out.