-
SQL JOINing a Table to Itself
23 March 2012
Read moreGetting two sets of information from one table in a select statement often leads people to write subselects, but it really doesn't matter that this is the same table twice, we can just give it a new alias and treat it as if it were a different table. This is one of those techniques where, once you've seen it, it's really obvious, but until that point it can be very confusing. I explained this to someone else recently, so I thought I'd capture it here in case it's helpful to anyone else.
Consider that tried-and-tested example: employees and managers. Here's the staff table from the database (today's imaginary data isn't particularly imaginative, sorry):
-
SQL Joins with On or Using
17 January 2012
Read moreI recently wrote a post about inner and outer joins, and a couple of people asked what the difference is between USING and ON.
-
Inner vs Outer Joins on a Many-To-Many Relationship
20 December 2011
Read moreSomeone will probably tell me that this is an elementary-level topic, but I got some good questions regarding joins from my most recent ZCE class students, so I thought I'd put down the examples that I used to explain this to them. Being able to join with confidence is a key skill, because it means that you can refactor and normalise your data, without worrying about how hard something will be to retrieve.