View a markdown version of this page

POSITIONAL joins - Amazon Athena

POSITIONAL joins

A POSITIONAL join pairs the first row of one source with the first row of the other, the second with the second, and so on. It takes no condition. If one source has more rows, the extra rows are kept, with NULL in the columns of the shorter source.

Syntax

from_item POSITIONAL JOIN from_item

Examples

The following SQL query pairs three letters with two numbers. The third letter has no partner, so its number is NULL.

SELECT l.letter, r.num FROM (VALUES ('a'), ('b'), ('c')) AS l(letter) POSITIONAL JOIN (VALUES (1), (2)) AS r(num) ORDER BY l.letter

The query returns the following results.

letter num

a

1

b

2

c

NULL

Considerations

Rows are paired in the order in which each source returns them. Because the order of rows read from a table is not guaranteed, use a positional join with sources whose row order is fixed, such as VALUES lists.