Database Reference
In-Depth Information
Figure 5-21. Using INNER 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 and their aliases you're joining and the kind of
join you're using:
from Production.Product PP inner join Production.ProductReview PPR
It specifies an inner join of the Production.Product and Production.ProductReview tables.
It also specifies the criteria for joining the primary key ProductID of the Product table with the
foreign key ProductId of the ProductReview table.
on PP.ProductID = PPR.ProductID
 
Search WWH ::




Custom Search