From Clause
- Last Updated: August 19, 2015
- 1 minute read
- DataDirect Connectors
- JDBC
- Apache Spark SQL 6.0
- Documentation
LEFT, RIGHT, and FULL OUTER JOINs are supported, as are LEFT SEMI JOINs and CROSS JOINs using the equal comparison operator, as shown in the following examples:
SELECT a.* FROM a JOIN b ON (a.id = b.id AND a.department = b.department)
SELECT a.val, b.val, c.val FROM a JOIN b ON (a.key = b.key1) JOIN c ON
(c.key = b.key2)
SELECT a.val, b.val FROM a LEFT OUTER JOIN b ON (a.key=b.key)
WHERE a.ds='2009-07-07' AND b.ds='2009-07-07'
However, the following syntax fails because of the use of non-equal comparison operators.
SELECT a.* FROM a JOIN b ON (a.id <>
b.id)
Spark SQL does not support join syntax in the form of a comma-separated list of tables. The driver, however, overcomes this limitation by translating the SQL into Spark SQL, as shown in the following examples.
| ANSI SQL-92 Query | Spark SQL Translation |
|---|---|
SELECT * FROM t1, t2 WHERE a =
b |
SELECT * FROM t1 t1 JOIN t2 t2 WHERE a =
b |
SELECT * FROM t1 y, t2 x WHERE a =
b |
SELECT * FROM t1 y JOIN t2 x WHERE a =
b |
SELECT * FROM t2, (SELECT * FROM t1)
x |
SELECT * FROM t2 t2 JOIN (SELECT * FROM
t1 t1) x |