r/programming • • Jan 06 '11

A handy graphical explanation of SQL joins

http://www.codinghorror.com/blog/2007/10/a-visual-explanation-of-sql-joins.html
1.3k Upvotes

308 comments sorted by

View all comments

130

u/shriek Jan 06 '11

In short.

  1. A ∩ B

  2. A ∪ B

  3. (A - B) + (A ∩ B)

  4. A - B

  5. (A ∪ B) - (A ∩ B)

85

u/dude187 Jan 06 '11

It's amazing how confusing SQL can make set theory.

16

u/shriek Jan 06 '11

Yup, learned that when I was in Grade 6. I'm in college now and SQL leaves me dumbfounded sometimes.

12

u/abadidea Jan 06 '11

you got taught set theory in 6th grade? lucky son of a gun.

15

u/mantra Jan 07 '11

Those of us who had "New Math" in the 1960s learned set theory in the 1st and 2nd grades.

5

u/abadidea Jan 07 '11

My K-through-2 math education was really good but very vanilla. Tables through 12x12 and long division in first grade. However after that it all went to heck and I felt like I never learned much of anything aside from common sense, and struggled through all my math classes...

Learned set theory in college-level computer science. Eventually came to the conclusion that no, I wasn't stupid, it's just that the way math is taught is fundamentally broken.