-2

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?

Almett
  • 876
  • 2
  • 11
  • 34
  • 1
    Maybe put in your post the many ways you tried. It could be some of them are close enough to be fixed with 1 or 2 adjustments. – JustLudo Aug 19 '22 at 06:33
  • @JustLudo such as `db.session.query(A).join(B,A.name == B.name, isouter=True).all()`. But this query gives out all data from the A. – Almett Aug 19 '22 at 06:37
  • The Venn diagram serves no purpose. We know what the code does. If the diagram were readable, it would add nothing. But: We don't know how to read the Venn diagram, because you don't give a legend & you mislabel it since none of the rows of the query result even have the same columns as the rows in tables A & B. Anyway tables aren't sets of rows, they are bags of rows. You are parroting something you have seen without actually understanding it & are not communicating anything by it. – philipxy Aug 19 '22 at 06:37
  • 1
    Please before considering posting: Pin down code issues via [mre]. Read the manual/reference & google any error message & many clear, concise & precise phrasings of your question/problem/goal, with & without your particular names/strings/numbers, 'site:stackoverflow.com' & tags; read many answers. Reflect research in posts. SO/SE search is poor & literal & unusual, read the help. Google re googling/searching, including Q&A at [meta] & [meta.se]. [How much research effort is expected of Stack Overflow users?](https://meta.stackoverflow.com/q/261592/3404097) [ask] [Help] – philipxy Aug 19 '22 at 06:46
  • Please either ask about 1 bad query/function with the obligatory [mre] & why you think it should return something else at the 1st subexpression that it doesn't give what you expect justified by reference to authoritative documentation or ask about your overall goal giving working parts you can do & ideally a [mre]. But please ask about the former 1st because misconceptions in the former will get in the way of understanding the latter. And bad code doesn't tell us what you wish it would do. [ask] [Help] – philipxy Aug 19 '22 at 07:20
  • 1
    @philipxy Appreciate your effort on my question. Either my non-native English was unable to articulate or simplify the question or the search engine didn't get me to that duplicate question. I will edit my question against the search engine and contributors of Stackoverflow. – Almett Aug 20 '22 at 09:48
  • I am always interested to know what people think one of these pseudo-Venn diagrams means, but they never say. Even when they say that such diagrams helped them a lot to understand joins. (People remove many diagrams though.) So if you don't mind: What did you originally think the sets & elements were? What did you think after my comment? (If the code had `select a.*` & both A & B had just 1 column then it would have returned close to SQL EXCEPT, close to set difference, which the diagram shows--but only close.) PS [Venn Diagram for Natural Join](https://stackoverflow.com/a/55642928/3404097) – philipxy Aug 20 '22 at 10:33

2 Answers2

1

Can be something like that:

db.session.query(A).outerjoin(B, A.name == B.name).filter(B.name == None)
Rasim Mammadov
  • 141
  • 1
  • 3
-2

A.join(B, A.id==B.id, isouter=True)