This website recently got a major rebuild; if you're missing something, let Lorna know.

    Tag: join


  1. SQL JOINing a Table to Itself


    Getting 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):

    Read more

  2. SQL Joins with On or Using


    I recently wrote a post about inner and outer joins, and a couple of people asked what the difference is between USING and ON.

    Read more

  3. Inner vs Outer Joins on a Many-To-Many Relationship


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

    Read more