Ha! Ha! On my previous attempts, I had something similar to this, but instead, I had
query = db.session.query(label('sid', distinct(a[1].c.patient_sid))) if (n > 1): for table in join_tables[1:]: for criterion in join_criteria[1:]: query = query.join(eval(table), eval(criterion)) Where the variables table and criterion were built lists, so that I ended up doing a Cartesian product of all my tables, which was giving me many problems, with aliasing being the least of it! Thanks! Greg-- On Tue, Mar 24, 2015 at 11:22 PM, Jonathan Vanasco <jonat...@findmeon.com> wrote: > any reason why you're not building a query like this? > > query = db.session.query(label('sid', > distinct(a[1].c.patient_sid))) > if n >= 2 > query = query.\ > join(a[2],a[2].c.patient_sid==a[1].c.patient_sid) > if n >= 3 > query = query.\ > join(a[3],a[3].c.patient_sid==a[1].c.patient_sid) > > or > > query = db.session.query(label('sid', > distinct(a[1].c.patient_sid))) > for i in range(2, n): > query = query.\ > join(a[i],a[i].c.patient_sid==a[1].c.patient_sid) > > > -- > You received this message because you are subscribed to a topic in the > Google Groups "sqlalchemy" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/sqlalchemy/SySyi4CCCUY/unsubscribe. > To unsubscribe from this group and all its topics, 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/d/optout. > -- Greg M. Silverman Senior Developer Analyst Cardiovascular Informatics <http://www.med.umn.edu/cardiology/> University of Minnesota 612-626-0919 g...@umn.edu › flora-script <http://flora-script.grenzi.org/> ‹ › grenzi.org ‹ › evaluate-it.org ‹ -- 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/d/optout.