Subquery
Subqueries, also known as nested queries or sub-selects, are the query methods in which SELECT subquery statements are embedded in another SQL query.
See the following subquery example:
SELECT * FROM t1 WHERE column1 = (SELECT column1 FROM t2);
In the example, SELECT * FROM t1 WHERE column1 is an external query (or an external statement), and (SELECT column1 FROM t2) is a subquery. Subquery statements must be written in brackets and then nested in external query statements, or nested in other subquery statements to form multi-layer nesting.
Main advantages of subquery:
-
Subqueries can divide statements and provide structured queries.
-
Subqueries can replace complex
JOINandUNIONSstatements. -
Subqueries are more readable than complex
JOINandUNIONS.
A subquery has the following categories:
- SELECT subquery
- FROM subquery
- WHERE Subquery
For more information, see:
- derived table
- Usage of subquery and comparison operators
- Usage of subquery with ANY or SOME operators
- Usage of subquery and ALL operator
- Usage of subquery and EXISTS operator
- Subquery and IN operator usage
limit
MatrixOne does not support selecting multiple columns for subquery.