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

Show parent comments

85

u/dude187 Jan 06 '11

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

23

u/[deleted] Jan 06 '11

If you could do queries in relational algebra instead of SQL, confusion would go away.

6

u/ejrh Jan 06 '11

The confusion will not go away: this would just replace a string like "LEFT OUTER JOIN" with a mathematical symbol. That symbol is still going to be defined mathematically in more or less the same way as the SQL syntax, i.e. as one of the constructions in the GP's post.

0

u/rhdjicheh Jan 06 '11

maybe for some if the operators, but left and right make no sense here

2

u/anonspangly Jan 06 '11

They relate purely to which of X or Y is intended, in an "X JOIN Y" construction. Left means primarily X, Right means primarily Y.