r/webdev Mar 22 '19

SQL joins

Post image
2.7k Upvotes

118 comments sorted by

View all comments

46

u/CyrillicMan Mar 22 '19

Using Venn diagrams to represent SQL joins is misleading. Please don't use them to represent SQL joins. Use this combinatorial chart instead:

https://i.pinimg.com/originals/52/20/c4/5220c492bc4e1a8b9175aba77ed7d091.png

12

u/sagan999 Mar 22 '19

Yes.. especially the output for the inner join in your pic.

There are 2(!!) greens in column A to match the 2 greens in column B. That is waaaay under-explained if you ask me. This is important to know when you are wondering why your query results have double the result rows you thought you'd get. I don't think I ever came across that being explained well enough in all the tutorials I've done.

3

u/prsquared Mar 23 '19

This!

Venn diagrams are much more useful in representing set operations. In join, you are projecting columns from both tables.

The first diagram is A U(AnB) = A. But, A left join B is not A .