# **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](derived-tables.md)
- [Usage of subquery and comparison operators](comparisons-using-subqueries.md)
- [Usage of subquery with ANY or SOME operators](subquery-with-any-some.md)
- [Usage of subquery and ALL operator](subquery-with-all.md)
- [Usage of subquery and EXISTS operator](subquery-with-exists.md)
- [Subquery and IN operator usage](subquery-with-in.md)

## **limit**

MatrixOne does not support selecting multiple columns for subquery.
