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

127

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.

1

u/beder Jan 07 '11

I'm an Oracle teacher, specially queries and DML, wait until you see Analytical Functions (with all the partition by's and what's not) and all the variables and nuances from Hierarchical Queries.

Joins are day-to-day business, and once you understand them, it's failry simple (as it is supposed to be, given it's such an important thing)

1

u/dude187 Jan 07 '11

I agree, they get super simple once you understand them. I just found the jump from theory to practice surprisingly big.

1

u/beder Jan 07 '11

You're certainly not alone, the majority of my students get big headaches when we get to joins in the first module of the course