How do I do a semijoin using SQLAlchemy?
- by Jason Baker
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.