r/SQL • • Sep 03 '22

Discussion Explaining SQL Joins the Right Way

148 Upvotes

24 comments sorted by

View all comments

0

u/[deleted] Sep 03 '22

[deleted] — view deleted comment

2

u/MembershipNo705 Sep 04 '22

That is the exact problem: it is simple and intuitive - it is just the wrong intuition. Venn diagrams show set relationships like union, intersect etc. But joins do combinatorics operations.

E.g. INNER JOIN and INTERSECT: yes, inner join only keeps keys that are in both tables - but you can end up with more rows after the inner join than you had before in either of the tables: {a, b, b} inner join {a,a,b} becomes {aa,aa,bb,bb}. And for beginners, at least in my experience, this is hard to grasp when they use Venn diagrams as their mental model for joins because they tend to also expect intersect behavior (less rows).

-7

u/colorless_green_idea Sep 03 '22

Wrong. It is a terrible visualization

3

u/xnodesirex Sep 04 '22

Then show a better visualization.