Database Reference
In-Depth Information
Output
+----------------+---------+---------+
| cust_name | cust_id | num_ord |
+----------------+---------+---------+
| Coyote Inc. | 10001 | 2 |
| Mouse House | 10002 | 0 |
| Wascals | 10003 | 1 |
| Yosemite Place | 10004 | 1 |
| E Fudd | 10005 | 1 |
+----------------+---------+---------+
Analysis
This example uses a left outer join to include all customers, even those who
have not placed any orders. The results show that customer Mouse House
(with 0 orders) is also included this time.
Using Joins and Join Conditions
Before wrapping up this two chapter discussion on joins, it is worthwhile to
summarize some key points regarding joins and their use:
Pay careful attention to the type of join being used. More often than
not, you'll want an inner join, but there are often valid uses for outer
joins, too.
Make sure you use the correct join condition, or you'll return incor-
rect data.
Make sure you always provide a join condition, or you'll end up with
the Cartesian product.
You may include multiple tables in a join and even have different
join types for each. Although this is legal and often useful, make sure
you test each join separately before testing them together. This makes
troubleshooting far simpler.
Summary
This chapter was a continuation of the previous chapter on joins. This chapter
started by teaching you how and why to use aliases, and then continued with
a discussion on different join types and various forms of syntax used with each.
You also learned how to use aggregate functions with joins, and some impor-
tant do's and don'ts to keep in mind when working with joins.
 
 
 
Search WWH ::




Custom Search