How do I do a semijoin using SQLAlchemy?

Posted by Jason Baker on Stack Overflow See other posts from Stack Overflow or by Jason Baker
Published on 2010-03-31T15:15:36Z Indexed on 2010/04/01 10:23 UTC
Read the original article Hit count: 210

Filed under:
|
|
|
|

http://en.wikipedia.org/wiki/Relational_algebra#Semijoin

Let's say that I have two tables: A and B. I want to make a query that would work similarly to the following SQL statement using the SQLAlchemy orm:

SELECT A.*
FROM A, B
WHERE A.id = B.id
AND B.type = 'some type';

The thing is that I'm trying to separate out A and B's logic into different places. So I'd like to make two queries that I can define in separate places: one where A uses B as a subquery, but only returns rows from A. I'm sure this is fairly easy to do, but an example would be nice if someone could show me.

© Stack Overflow or respective owner

Related posts about python

Related posts about sqlalchemy