How to use the LEFT vs. RIGHT OUTER JOIN in SQL

Monday Mar 10th 2008 by DatabaseJournal.com Staff
Share:

Learn about LEFT vs. RIGHT OUTER JOINs in SQL queries when using OUTER JOIN for multiple tables. In this book excerpt, also see how to use the SELECT statement and embed SQL JOINs.

[From SearchSQLServer]

You'll generally use the OUTER JOIN form that asks for all the rows from one table or result set and any matching rows from a second table or result set. To do this, you specify either a LEFT OUTER JOIN or a RIGHT OUTER JOIN.

What's the difference between LEFT and RIGHT? Remember from the previous chapter that to specify an INNER JOIN on two tables, you name the first table, include the JOIN keyword, and then name the second table. When you begin building queries using OUTER JOIN, the SQL Standard considers the first table you name as the one on the "left," and the second table as the one on the "right." So, if you want all the rows from the first table and any matching rows from the second table, you'll use a LEFT OUTER JOIN. Conversely, if you want all the rows from the second table and any matching rows from the first table, you'll specify a RIGHT OUTER JOIN.

The article continues at http://searchsqlserver.techtarget.com/generic/0,295582,sid87_gci1286374,00.html

Share:
Home
Mobile Site | Full Site
Copyright 2017 © QuinStreet Inc. All Rights Reserved