Database Reference
In-Depth Information
Try It: Using RIGHT OUTER JOIN
To list all ProductID and ProductName columns and details based on those that have been reviewed,
open a New Query window in SQL Server Management Studio (remember to make AdventureWorks
your query context). Enter the following query, and click Execute. You should see the results shown in
Figure 5-23.
select PP.ProductID, PP.Name, PPR.ReviewerName, PPR.Comments, PPR.Rating
from Production.Product PP right outer join Production.ProductReview PPR
on PP.ProductID = PPR.ProductID
Figure 5-23. Using LEFT OUTER JOIN
How It Works
Let's start with the SELECT list.
select PP.ProductID, PP.Name, PPR.ReviewerName, PPR.Comments, PPR.Rating
Since you're selecting columns from two tables, you need to identify which table a column comes
from, which you do by prefixing the table name and a dot (.) to the column name. This is known as
disambiguation, or removing ambiguity so the database manager knows which column to use. Though
this has to be done only for columns that appear in both tables, the best practice is to qualify all columns
with their table names.
The following FROM clause specifies both the tables you're joining and the kind of join you're using:
from Production.Product PP right outer join Production.ProductReview PPR
 
Search WWH ::




Custom Search