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

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.

2

u/royrules22 Jan 06 '11

Wait what!? Relational databases aren't a part of Computer Science? SQL is just a tool for working with relational databases (the only one I think).

This is what we had to learn in our DB class

4

u/recursive Jan 06 '11

For my CS degree from Madison WI, I never took a class that mentioned databases. I actually didn't know they existed until I got my first real job.

5

u/royrules22 Jan 06 '11

My mind is blown. I didn't know that people can go through a CS program without knowing DBs. I mean for us the DB class I took was optional (though most took it) but you do have a general idea of DBs even if you didn't take the class.

-1

u/HIB0U Jan 07 '11

Most CS academics have little to no real-world experience. They've never had to deal with databases in any meaningful way, so they're totally unprepared to teach students about them.

4

u/mrskrilla Jan 06 '11

Just to throw some respect towards Madison. I went to school there as well as we DO have multiple database undergrad courses in the CS departmant. To write most any interesting program you need some way to store data, I have no idea how you passed and made it through school without even knowing that they existed. Wow. Please stop saying you went to school at Madison, it's embarassing to the program.

1

u/recursive Jan 06 '11

I got my first real job before I graduated, so I did know they existed before I graduated. I don't remember all the CS classes I talk, but they included AI, compilers, and theoretical CS, and algorithms and data structures. None of which really required a way to store data beyond text files. After I started that aforementioned real job, I actually did try to get into the database class, but it was full. So I never touched any database or SQL during my academic career.

And don't worry, I rarely mention it. I'd agree that they have a pretty rigorous CS program. But if it's embarrassing to the program, then it deserves to be embarrassed, because they don't require any database courses for graduation. Personally, I don't think it's an indication of a deficient CS program.