A JOIN predicate (join_predicate) specifies a JOIN. A JOIN predicate can be specified with one, two, or no OUTER JOIN indicators.
<join_predicate> ::=
<expression>
[<outer_join_indicator>] <comp_op> <expression>
[<outer_join_indicator>]
<outer_join_indicator> ::= (+)
<comp_op> ::= < | > | <> | != | =
| <= | >=
| ~= |
~< |
~> (for computers with ASCII code)
Each expression must contain a column specification. A column specification must exist for the first and second expression so that both specifications refer to different table names or reference names.
Let x be the value of the first expression and y the value of the second expression. The values x and y must be comparable with one another.
The rules for comparison predicates apply here.
If at least one OUTER JOIN indicator outer_join_indicator is specified in a JOIN predicate of a search condition, the corresponding table expression must be based on exactly two tables, or the following must apply:
· OUTER JOIN indicators are specified for only one of the tables in the FROM clause.
· All of the JOIN predicates in this table to just one other table contain the OUTER JOIN indicator.
· All other JOIN predicates contain no OUTER JOIN indicators.
If a JOIN requires more than two tables for the QUERY specification and if one of the rules above cannot be observed, a QUERY expression can also be used in the FROM clause.
Table rows are transferred to the result table only if they have a counterpart of the comparison operator comp_op in the other table specified in the JOIN predicate.
If each row in a
table is to appear at least once in the result table, the OUTER JOIN indicator
must be specified on the side of the comparison operator where the other table
is specified.
If it is not possible to find at least one counterpart for a table row in the
other table, a row is still created for that table row in the result table.
The NULL value is then used for the output columns which are formed from the
columns in the other table.
Since the OUTER JOIN indicator can be specified on both sides of the
comparison operator if the table expression
is based on just two tables, it can be ensured that each line in both tables
appears at least once in the result table.
The JOIN predicate is a special case of the comparison predicate. The number of JOIN predicates in a search condition is limited to 128.
JOIN predicate
SELECT reservation.rno, customer.name,
customer.firstname, reservation.arrival, reservation.departure
FROM customer, reservation
WHERE customer.name = 'Porter' AND customer.cno =
reservation.cno
Is there a reservation for the customer 'Porter'? If so, for what date?
RNO |
NAME |
FIRSTNAME |
ARRIVAL |
DEPARTURE |
100 |
Porter |
Jenny |
2004-11-13 |
2004-11-15 |
110 |
Porter |
Jenny |
2004-12-24 |
2005-01-06 |
Specifying an OUTER JOIN indicator
SELECT hotel.hno, hotel.name, reservation.rno
FROM hotel, reservation
WHERE hotel.zip = '10019' AND hotel.hno =
reservation.hno (+)
List all the hotels in the location with zip cope 10019 for which reservations exist as well as those for which a reservation does not exist. Missing reservation numbers are assigned a NULL value.
HNO |
NAME |
RNO |
80 |
Midtown |
100 |
80 |
Midtown |
140 |
40 |
Eight Avenue |
? |