Database Reference
In-Depth Information
15
Joining Tables
In this chapter, you learn what joins are, why they are used, and how to create
SELECT statements using them.
Understanding Joins
One of SQL's most powerful features is the capability to join tables on-the-fly
within data retrieval queries. Joins are one of the most important operations
you can perform using SQL SELECT , and a good understanding of joins and
join syntax is an extremely important part of learning SQL.
Before you can effectively use joins, you must understand relational tables
and the basics of relational database design. What follows is by no means a
complete coverage of the subject, but it should be enough to get you up and
running.
Understanding Relational Tables
The best way to understand relational tables is to look at a real-world example.
Suppose you had a database table containing a product catalog, with each cata-
log item in its own row. The kind of information you would store with each
item would include a product description and price, along with vendor infor-
mation about the company that creates the product.
Now suppose you had multiple catalog items created by the same vendor.
Where would you store the vendor information (things such as vendor name,
address, and contact information)? You wouldn't want to store that data along
with the products for several reasons:
Because the vendor information is the same for each product that ven-
dor produces, repeating the information for each product is a waste of
time and storage space.
If vendor information changes (for example, if the vendor moves or
his area code changes), you would need to update every occurrence of
the vendor information.
 
 
 
 
Search WWH ::




Custom Search