tags:

views:

1307

answers:

1

According to the join-op syntax, SQLite has 13 distinct join statements:

,
JOIN
LEFT JOIN
OUTER JOIN
LEFT OUTER JOIN
INNER JOIN
CROSS JOIN
NATURAL JOIN
NATURAL LEFT JOIN
NATURAL OUTER JOIN
NATURAL LEFT OUTER JOIN
NATURAL INNER JOIN
NATURAL CROSS JOIN

Are they all unique? Which are equivalent?

+7  A: 

The SQLite grammar is a bit different from the SQL-92 spec's, according to which, the following are illegal:

*OUTER JOIN
*NATURAL OUTER JOIN
*NATURAL CROSS JOIN

The first two, because a <join type>, in order to contain OUTER, must also include an <outer join type> before it. The last, because NATURAL can only occur in <qualified join>'s, not <cross join>'s. These don't appear to behave according to any spec, so it's a good idea to avoid them.

As was answered on the mailing list, SQLite3 only supports three joins: CROSS JOIN, INNER JOIN, and LEFT OUTER JOIN. The following are equivalent:

, == CROSS JOIN
JOIN == INNER JOIN
LEFT JOIN == LEFT OUTER JOIN

As explained in the wikipedia article the NATURAL keyword is shorthand for finding and matching on same-name columns, and doesn't affect the the join type.

According to the SQLite page, 'RIGHT' and 'FULLOUTER JOIN's are not supported.

Andrey Fedorov
No RIGHT OUTER or FULL OUTER support?
Joel Coehoorn
Nope, and let me add that explicitly, thanks.
Andrey Fedorov