JOIN Predicate (join_predicate)

A JOIN predicate (join_predicate) is a predicate that specifies a join.

A join is an SQL statement that links several tables with each other and returns a join table as its result.

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> ::= (+)

<comp_op> ::= < | > | <> | != | = | <= | >=
|
~= | ~< | ~> (for computers with ASCII code)

Examples

SQL Tutorial, Joins: Information from Several Tables

Explanation

Each expression (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 JOIN predicate is a special type of comparison predicate. The rules for a comparison predicate 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 only specified for 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, 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 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.

See also:

Join Table (joined_table)

Join view table in an INSERT statement

Updateable Join View Table (CREATE VIEW Statement)

Restrictions for SQL Statements

Concepts of the Database System, search strategies for Joins, EXPLAIN Statement for Joins