Peter L. Buschman wrote:
Apologies since this seems like a basic question, but what is the best
practice syntax for performing
multiple joins against a single table? The documentation examples
clearly demonstrate how to join
2 tables together, but examples with 3 or more are unclear.
For example, it seemed like this should work:
query = select([table1, table2, table3], ((table1.c.foo_id ==
table2.c.foo_id) and (table2.c.bar_id == table3.c.bar_id)))
Using and_() should do the trick here:
query = select([table1, table2, table3], and_(table1.c.foo_id ==
table2.c.foo_id, table2.c.bar_id == table3.c.bar_id))
or perhaps more explicitly/verbosely (as shown in the Inner and Outer Joins
section of the documentation -
http://www.sqlalchemy.org/docs/sqlconstruction.myt#constructing_join
query = select([table1, table2, table3], from_obj=[
table1.join(
table2, table2.c.foo_id==table1.c.foo_id).join(
table3, table3.c.bar_id==table2.c.bar_id)
])
HTH
Robert
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users