thinQmaster Virtual testing partner Adaptive practice exams that find your weak spots and drill them. Every answer explained. From $69
Enroll

thinQmaster

Find your exam

Five questions free, before you decide.

Step 1 · choose a vendor

In one of our camps? Your practice exams come with the tuition — they are on your study page already.

Data & Analytics · Foundational

Subquery

A query nested inside another statement, used as a value, a list, or a derived table.

Definition

Subqueries can be scalar (return one value), multi-row (used with IN, ANY or ALL) or table-valued (derived tables in FROM). They can appear in SELECT, FROM, WHERE and HAVING. CTEs often improve the readability of complex nested subqueries.

Example

SELECT * FROM Products WHERE Price > (SELECT AVG(Price) FROM Products);

Exam tip

A scalar subquery that returns more than one row raises a runtime error.

Related terms