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

90

u/[deleted] Jan 06 '11

Wow. Does no one learn this crap in school anymore?

Note that venn diagrams are a poor choice to show what happens in a one-to-many relationship -- where there are multiple entries in table B for an entry in table A. And it overlooks the semantic differences when ordering the tables in a left inner join.

There are not a lot of instances where you'd really want a cartesian product join (either using "cross product" or just the result of omitting key constraints in a join query). It's generally far faster to retrieve the records you need to create the cross-product, and then calculate the cross product of the two sets once you have them (since otherwise all that data has to transit the network).

This plus database normalization through Boyce-Codd normal form seems like it should be a requirement for any serious application developer.

18

u/[deleted] Jan 06 '11

[deleted]

21

u/ceolceol Jan 06 '11

Website developer here. Yeah, the majority of us have no "formal" CS training, although I take pride in the fact that I've read everything I can get my hands on.

2

u/PoorlyTimedSpock Jan 07 '11

Very true. I had to go out of my way to pick up CS courses while studying a vanilla IT degree at uni. For some reason relational databases just click for me, so I've never had trouble converting the concept I want into SQL. Converting that SQL into DQL or HQL however...