How to query two tables to get data from either of them that's distinct from another?
Question:
I need to get left join results from two tables table1
and table2
.
My SQL query gives me the desired result.
select *
from table1 left join table2
on table1.name=table2.name where table2.name is null;
How do I turn this into a Flask SQLAlchemy query?
Answers:
A.join(B, A.id==B.id, isouter=True)
Can be something like that:
db.session.query(A).outerjoin(B, A.name == B.name).filter(B.name == None)
I need to get left join results from two tables table1
and table2
.
My SQL query gives me the desired result.
select *
from table1 left join table2
on table1.name=table2.name where table2.name is null;
How do I turn this into a Flask SQLAlchemy query?
A.join(B, A.id==B.id, isouter=True)
Can be something like that:
db.session.query(A).outerjoin(B, A.name == B.name).filter(B.name == None)