Joining Tables in T-SQL

Joining Tables in T-SQL: Joining Tables in T-SQL: an overview, INNER JOIN, OUTER JOIN, Joining Multiple Tables.

Updated

  1. Joining Tables in T-SQL: an overview (Apprentice): A join puts related rows from two tables side by side, matched on their key columns. An inner join keeps only matches; an outer join also keeps the rows with no match.
  2. INNER JOIN (Journeyman): INNER JOIN combines two tables on a matching column, keeping only rows that match. Table aliases keep it short, and the joined columns can be filtered, grouped and sorted like any others.
  3. OUTER JOIN (Journeyman): LEFT JOIN keeps every row of the first table, matched or not; RIGHT JOIN keeps every row of the second; FULL OUTER JOIN keeps both. Rows with no match get NULL, which also lets you find what's missing.
  4. Joining Multiple Tables (Journeyman): Joins chain: each JOIN adds one more table, linked by its key to a table already in the query. A many-to-many link goes through its associative table, and a table can even join to itself.