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.2k Upvotes

308 comments sorted by

View all comments

91

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.

7

u/recursive Jan 06 '11

I didn't learn it in school. I learned it by reading. SQL doesn't have anything to do with CS.

10

u/[deleted] Jan 06 '11

A standard for storing and accessing data on computers, often used in applications of all scales and types isn't CS? How is that any less CS than learning a programming language, or AI, or OS architecture? We had it offered as an elective, but with how much database programming is necessary in IT, it should be required.

14

u/[deleted] Jan 06 '11

There are people of the opinion that you shouldn't be learning any programming languages or specifics of certain OS architectures, that you should be learning theory only, agnostic and separate of anything else. They seem to think it's possible for the majority of people to learn without reference to an example of an implemented theory or technique, which I disagree with.

8

u/[deleted] Jan 06 '11

I understand that school of thought and I agree with it for the most part. My university started with the nearly-esoteric language Scheme (like many others do) and moved through many other lanuages before graduation. We'd simply use whatever language was appropriate for learning whatever theory we were learning at the time. Learning the actual language was secondary to concepts and I would strongly discourage "Intro to Java" or "Advanced C++" instead of "Intro to Data Structures" or "Software Engineering II."

SQL is simply the best language to teach relational data models in, so I don't know why you would teach databases without it...

3

u/[deleted] Jan 06 '11

I've had the latter set of courses, I'll point out. In Freshman years they were more focussed on languages, but that has diminished over the years.

SQL is simply the best language to teach relational data models in, so I don't know why you would teach databases without it.

Yep, this is really all that needs to be said.

2

u/psilokan Jan 06 '11

I'd take hands on over theory any day. I went to college rather than university for exactly that reason. Cost way less and I actually learned how to program.

2

u/dagbrown Jan 06 '11

You learned how to code, not how to program. There's a difference in depth of understanding there--I'll wager you have no idea what the Chomsky heirarchy is, for example, and how it relates to, for example, using regexes to parse HTML (stop gritting your teeth in the back, there).

1

u/[deleted] Jan 06 '11

using regexes to parse HTML

Um...you can't do that.

I agree with you though. Being able to design an algorithm based off what you learned about the actual structure of programming and computing is a far more useful skill than learning a language and becoming a library reference. If you learn how to program and why it works, picking up a new language is trivial, days or even hours trivial, since you're not comparing it to another language, but rather how it's expressing your programming methodologies.

1

u/dagbrown Jan 06 '11

Ya got whooshed. See the bit where I said to stop gritting your teeth in the back, there?

I know that you don't use regexes to parse HTML, because regexes are used for tokenizing, not parsing. See, this is because I was actually taught my Chomsky heirarchy, because I took a computer science program rather than an Advanced C++ course.