Java Reference
In-Depth Information
It is important to note that "left" and "right" are completely dependent on the order of the tables in the
SQL statement, so you can turn this into a
RIGHT OUTER JOIN
by reversing the order of the tables in
the
JOIN
command. Here's an example:
SELECT c.Last_Name + ', ' + c.First_Name AS Customer,
o.Order_Date
FROM ORDERS o RIGHT OUTER JOIN
CUSTOMERS c ON c.customer_number = o.customer_number;
OUTER JOIN
commands can also be written in shorthand similar to the form we use for our
INNER
JOIN
. This is the form for the
LEFT OUTER JOIN
:
SELECT c.Last_Name + ', ' + c.First_Name AS Customer,
o.Order_Date
FROM CUSTOMERS c, ORDERS o
WHERE c.customer_number *= o.customer_number;
The form for the
RIGHT OUTER JOIN
follows:
SELECT c.Last_Name + ', ' + c.First_Name AS Customer,
o.Order_Date
FROM ORDERS o, CUSTOMERS c
WHERE o.customer_number =* c.customer_number;
Note
In the shorthand version, the type of JOIN depends on both the order of the tables in the
FROM clause, and the position of the asterisk in the *= operator.
FULL OUTER JOIN
A
FULL OUTER JOIN
includes all unmatched rows from both tables in the result. For example, to find
any orders in the Orders Table with customer numbers that do not match any entries in our Customers
Table, you can execute a Full Outer Join to show all the entries in both tables, as shown in
Figure 9-7
.