SQL JOINs should not be associated with Venn diagrams.

Ivo Stratev
2 min readMar 18, 2021

From time to time I see pictures like the one I drew on WEB pages which try to explain SQL JOINs…

Those pictures “try to show the difference between the different SQL JOINs” with Venn diagrams. And here is the thing SQL JOINs are for joining data…

All those pictures out there on WEB are trying to demonstrate the difference by showing which records are used in the most general case for creating the result of the join operation. The main problem is that joins are all about joining records from two tables. And the result from the join operation is what really matters and it is what should be shown, not which records are used to produce this result.

Also, Venn diagrams are used for representing sets and not multisets and I hope we all know that Database systems that support SQL are not really relational but rather multi-relational.

I mentioned the term multiset because it's possible that when joining two tables some records can be used more than once for constructing the result.

Also almost in all cases, the two tables that are joined have totally different schema and this implies that the “intersection” of the records is empty… If we consider that on the Venn diagrams are actually shown IDs instead of records (the records are projected) then yeah the “intersection” is probably non-empty but I don’t believe that’s the case with the diagrams on the Internet.

--

--

Ivo Stratev

Passionate about Programming. Interested in Highly Distributed Systems and the Microservice Architecture. In love with Math and proving things.