Referencing tables in an ON clause

The tables that are referenced in an ON clause must be part of the join that the ON clause modifies. For example, the following is invalid:

FROM ( A KEY JOIN B ) JOIN ( C JOIN D ON A.x = C.x )

The problem is that the join condition A.x = C.x references table A, which is not part of the join it modifies (in this case, C JOIN D).

However, as of the ANSI/ISO standard SQL99 and Adaptive Server Anywhere 7.0, there is an exception to this rule: if you use commas between table expressions, an ON condition of a join can reference a table that precedes it syntactically in the FROM clause. Therefore, the following is valid:

FROM (A KEY JOIN B) , (C JOIN D ON A.x = C.x)

See also: Key joins.

For more information about commas, see Commas.

 Example