Mega Code Archive

 
Categories / MSSQL Tutorial / Table Join
 

SQL Server 2005 join types fall into three categories

Inner joins use the INNER JOIN keywords.  INNER JOIN operates by matching common values between two tables.  Only table rows satisfying the join conditions are used to construct the result set. INNER JOINs are the default JOIN type. You can use just the JOIN keyword in your INNER JOIN operations. Outer joins have three different join types: LEFT OUTER, RIGHT OUTER, and FULL OUTER joins.  LEFT OUTER and RIGHT OUTER JOINs return rows that match the conditions of the join condition.  LEFT OUTER JOINs return unmatched rows from the first table of the join pair. RIGHT OUTER JOINs return unmatched rows from the second table of the join pair.  The FULL OUTER JOIN clause returns unmatched rows on both the left and right tables. A CROSS JOIN returns a Cartesian product when a WHERE clause is not used.  A Cartesian product produces a result set based on every possible combination of rows from the left table, multiplied against the rows in the right table.  If the table A has 7 rows, and the table B has 22 rows, you would receive 154 rows (or 7 times 22) in the query results.