0

I'm trying to map this "simple" SQL-Statement into SQL-Alchemy

    select DISTINCT cv.*, ct."name"
    from "CarVariants" cv,
    "Cars" ca,
    "CarTypes" ct
    where cv."f_keyNumber" = ca."keyNumber"
    and cv."carType" = ca."carType"
    and cv."carType" = ct."f_carType"
    and "f_keyNumber" = '12345'
    and "f_carId" = 1

Something like this:

variants = self.em.CarVariants.createQuery();

variants = variants.filter_by(f_keyNumber=12345, f_carId = 1).distinct()

How do I add the "and"-relations (Cars, CarTypes) ?

1 Answer 1

1

Use and_

from sqlalchemy import and_
variants = variants.filter_by(and_(cond_1,cond_2....cond_n)).distinct()

See this page for further reference:
http://docs.sqlalchemy.org/en/rel_0_8/orm/tutorial.html

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.