# 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:

```sql
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 `JOIN` and `UNIONS` statements.

- Subqueries are more readable than complex `JOIN` and `UNIONS`.

**A subquery has the following categories**:

- SELECT subquery
- FROM subquery
- WHERE Subquery

For more information, see:

- [derived table](https://omnifabric.cloudsigma.com/docs/reference/sql/SQL-Reference/Data-Query-Language/subqueries/derived-tables.html.md)
- [Usage of subquery and comparison operators](https://omnifabric.cloudsigma.com/docs/reference/sql/SQL-Reference/Data-Query-Language/subqueries/comparisons-using-subqueries.html.md)
- [Usage of subquery with ANY or SOME operators](https://omnifabric.cloudsigma.com/docs/reference/sql/SQL-Reference/Data-Query-Language/subqueries/subquery-with-any-some.html.md)
- [Usage of subquery and ALL operator](https://omnifabric.cloudsigma.com/docs/reference/sql/SQL-Reference/Data-Query-Language/subqueries/subquery-with-all.html.md)
- [Usage of subquery and EXISTS operator](https://omnifabric.cloudsigma.com/docs/reference/sql/SQL-Reference/Data-Query-Language/subqueries/subquery-with-exists.html.md)
- [Subquery and IN operator usage](https://omnifabric.cloudsigma.com/docs/reference/sql/SQL-Reference/Data-Query-Language/subqueries/subquery-with-in.html.md)

## limit

MatrixOne does not support selecting multiple columns for subquery.
