sqlcmd.net validated sql reference

#subquery

Commands grouped around the same concept, pattern, or recurring problem.

8 commands with this tag Browse related patterns quickly
advanced deleting MySQL MariaDB SQL Server PostgreSQL SQLite

Delete Rows Based On A Condition In Another Table

Remove rows from one table when a matching row exists in another table using a subquery.

intermediate subqueries MySQL MariaDB SQL Server PostgreSQL SQLite

Filter Rows Using A Correlated Subquery

Reference the outer query's current row inside a subquery to compute a per-row comparison value.

intermediate subqueries MySQL MariaDB SQL Server PostgreSQL SQLite

Nest A Query Inside Another With Subqueries

Embed a `SELECT` inside another query to filter, compute, or supply values that depend on aggregated or derived data.

advanced joining MySQL SQL Server PostgreSQL

Reference Outer Columns Inside a Subquery With LATERAL

Use `LATERAL` (or `CROSS APPLY` on SQL Server) to let a subquery reference columns from the preceding table in the `FROM` clause.

advanced filtering MySQL MariaDB SQL Server PostgreSQL SQLite

Test For Row Existence With EXISTS

Use a correlated subquery inside `EXISTS` to include rows only when related rows are found in another table.

intermediate updating MySQL MariaDB SQL Server PostgreSQL SQLite

Update Rows Selected By A Subquery

Use a subquery in the `WHERE` clause of an `UPDATE` to restrict which rows are modified based on data from another table.

intermediate subqueries MySQL MariaDB SQL Server PostgreSQL SQLite

Use A Subquery As A Derived Table In FROM

Wrap a `SELECT` in the `FROM` clause to create a temporary result set you can filter or join against as if it were a real table.

intermediate null-handling MySQL MariaDB SQL Server PostgreSQL SQLite

Use NOT IN Safely When NULLs Are Possible

Filter `NULL` values out of the right side before using `NOT IN`, or the predicate can exclude everything.