A SELECT statement nested inside another query, used in WHERE, FROM, SELECT, or HAVING clauses.
A query nested inside another query, useful for filtering, computed columns, or derived tables. Correlated subqueries (that reference outer rows) can be slow; always check if a JOIN or window function can replace them for better performance.
| Database System | Support Status | Since Version | Notes |
|---|---|---|---|
| MySQL | ✓ Supported | all | All subquery types supported. Optimization historically weak in older versions — greatly improved in 8.0 with hash joins and derived condition pushdown. |
| PostgreSQL | ✓ Supported | all | Excellent support for all subquery types. Also supports LATERAL subqueries and efficient EXISTS/NOT EXISTS. |
| SQL Server | ✓ Supported | all | Full support for scalar, correlated, and derived-table subqueries. |
| Oracle | ✓ Supported | all | Full support. Scalar subqueries can appear in SELECT lists and many other expression contexts. |
| SQLite | ✓ Supported | all | Full support for correlated subqueries, EXISTS, and derived tables. |
Subqueries can often be rewritten as JOINs or CTEs for readability or performance. MySQL pre-8.0 had known optimizer issues with IN subqueries that were fixed in 8.0.
All subquery types supported. Optimization historically weak in older versions — greatly improved in 8.0 with hash joins and derived condition pushdown.
Excellent support for all subquery types. Also supports LATERAL subqueries and efficient EXISTS/NOT EXISTS.
Full support for scalar, correlated, and derived-table subqueries.
Full support. Scalar subqueries can appear in SELECT lists and many other expression contexts.
Full support for correlated subqueries, EXISTS, and derived tables.