-
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.