Thank you, it works!

On Feb 27, 5:51 am, Michael Bayer <[email protected]> wrote:
> Nobody seems to be answering this one so here you go:
>
> from sqlalchemy import and_
>
> session.query(
>               T1.c11, T1.c12, T2.c23).join(
>                   T2, and_(
>                             T1.c11==T2.c21,
>                             T1.c12==T2.c22,
>                             T2.c24 > xx)
>                  )
>
> relevant concepts:
>
> querying individual 
> columns:http://docs.sqlalchemy.org/en/latest/orm/tutorial.html#querying
> comparison operations, 
> AND:http://docs.sqlalchemy.org/en/latest/orm/tutorial.html#common-filter-...
> joining:http://docs.sqlalchemy.org/en/latest/orm/tutorial.html#querying-with-...
>
> On Feb 26, 2012, at 10:12 AM, Flair wrote:
>
>
>
>
>
>
>
> > Hi all,
>
> > Suppose I have two tables t1 and t2 defined as following declarative
> > classes.
> > There is no foreign key setup in database between these two tables and
> > I want to write the join statement in sqlalchemy format which equates
> > to sql like this:
>
> > select t1.c11, t1.c12, t2.c23
> > from t1 join t2
> > on t1.c11==t2.c21 and
> >     t1.c12==t2.c22 and
> >     t2.c24 > xx;
>
> > Anyone could inform me how to achieve this?
>
> > class T1(object):
>
> >    __tablename__ = 't1'
>
> >    _id = Column('id', Integer, primary_key = True)
> >    c11 = Column('c11', Integer)
> >    c12 = Column('c12', Integer)
>
> > class T2(object):
>
> >    __tablename__ = 't2'
>
> >    _id = Column('id', Integer, primary_key = True)
> >    c21 = Column('c21', Integer)
> >    c22 = Column('c22', Integer)
> >    c23 = Column('c23', Integer)
> >    c24 = Column('c24', Integer)
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "sqlalchemy" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to 
> > [email protected].
> > For more options, visit this group 
> > athttp://groups.google.com/group/sqlalchemy?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to