A JOIN
predicate specifies a JOIN. A JOIN predicate can be specified with or without one or with two OUTER JOIN indicators.Syntax
<join_predicate> ::=
<expression> [<outer_join_indicator>] <comp_op> <expression> [<outer_join_indicator>]
<outer_join_indicator> ::= (+)
expression, comp_opExplanation
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 outlined under
comparison predicate apply here.If at least one 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 has to apply: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.Only those rows from the table that have a counterpart of the comparison operator in the JOIN predicate specified in the table are transferred to the result table.
The OUTER JOIN indicator must be specified on the side of the comparison operator where the other table is specified if each row in a table is to appear at least once in the result table.
If it is not possible to find at least one counterpart for a table row in the other table, this row is used to build a row for 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
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
Model tables
Is there a reservation for the customer 'Porter'? If so, for what date?
SELECT reservation.rno, customer.name, reservation.arrival, departure
FROM customer, reservation
WHERE customer.name = 'Porter' AND customer.cno = reservation.cno
RNO |
NAME |
ARRIVAL |
DEPARTURE |
100 |
Porter |
13.11.1998 |
15.11.1998 |
110 |
Porter |
24.12.1998 |
06.01.1999 |
Specifying an OUTER JOIN indicator
Model tables hotel, reservation
List all the hotels in Chicago for which a reservation exists and those for which a reservation does not exist. Missing reservation numbers are assigned a NULL value.
SELECT hotel.hno, hotel.name, reservation.rno
FROM hotel, reservation
WHERE hotel.city = 'Chicago' AND hotel.hno = reservation.hno (+)
HNO |
NAME |
RNO |
40 |
Eight Avenue |
? |
50 |
Lake Michigan |
120 |
80 |
Midtown |
100 |
80 |
Midtown |
140 |