Previous |
Next
What is SQL OUTER JOIN?The SQL OUTER JOIN clause is a variation of the SQL JOIN clause enables a SELECT statement to access more than one table. The JOIN clause controls how tables are linked. It is a qualifier of the SQL FROM clause. The OUTER JOIN clause differs from the standard JOIN clause (also known as the INNER JOIN clause) in that rows are returned even when there are no matches through the JOIN critieria on the second table. Why Use SQL OUTER JOIN?Use the SQL OUTER JOIN whenever multiple tables must be accessed through a SQL SELECT statement and results should be returned if there is not a match between the JOINed tables. How To Use SQL OUTER JOINSQL OUTER JOIN is used as follows. The ON clause describes the conditions of the JOIN. Important! A "cartesian product" can result if there is no relating the tables for the join. A row would be included for each combination between the two tables so if one table has 1,000 rows and the second table has 2,000 rows then 2,000,000 rows would be returned. Important! If there are matches on the JOIN criteria then rows will still be returned. This is known an "OUTER JOIN". Use the "INNER JOIN" in cases where no rows should be returned when one side of the join is missing. SQL OUTER JOIN Syntax
SQL OUTER JOIN Example The following example JOINs the region and branch tables on the region_nbr column. Here are the contents of the tables:
Table: REGION
Table: BRANCH
This SQL Statement with OUTER JOIN is executed:
Here is the result. Note that the "Virtual Region" is included in the results even though it has no rows in the branch table. This is the difference between the INNER JOIN and OUTER JOIN.
|
SQL Cookbook
by Anthony Molinaro
SQL: Visual QuickStart Guide (2nd Edition) by Chris Fehily
SQL Bible by Alex Kriegel, Boris M. Trukhnov
SQL: The Complete Reference, Second Edition by James R Groff, Paul N. Weinberg
Joe Celko's SQL for Smarties: Advanced SQL Programming Third Edition by Joe Celko
Murach's SQL for SQL Server by Bryan Syverson
| HOME | SQL OVERVIEW | SQL BASICS | SQL ADMINISTRATION | SQL ADVANCED | SQL SYNTAX |
| Copyright© 1999-2006, First Place Software, Inc. |


