skip to main content
SQL Functionality for the Driver for Apache Spark SQL : Subqueries
  

Try DataDirect Drivers Now

Subqueries

A query is an operation that retrieves data from one or more tables or views. In this reference, a top-level query is called a Select statement, and a query nested within a Select statement is called a subquery.
Subqueries are supported, with the following Entry SQL level restriction: subqueries can only exist in the FROM clause, that is, in a derived table. In the following example, the second Select statement is a subquery:
SELECT * FROM (SELECT * FROM t1 UNION ALL SELECT * FROM t2) sq
Although Apache Spark SQL currently does not support IN or EXISTS subqueries, you can efficiently implement the semantics by rewriting queries to use LEFT SEMI JOIN.