SQL

Subqueries

Learn how to nest queries within queries.

By TechCoder TeamLast updated: 2026-06-02
In a Nutshell

Learn how to nest queries within queries. This hands-on tutorial focuses on practical implementation of subqueries concepts.

What is a Subquery?

A subquery is a query nested inside another query. It can be used in SELECT, FROM, WHERE, and other clauses.

Subqueries are executed first, and their result is passed to the outer query.

Single-Row Subquery

A single-row subquery returns one row with one column. It is often used with comparison operators (=, >, <).

Example: Products More Expensive than Average

Find all products that have a price higher than the average price.

SQL PLAYGROUND
⏳ Loading editor…

Multi-Row Subquery

A multi-row subquery returns multiple rows. It is often used with the IN operator.

Example: Customers who have ordered "Chais"

Note: Since our simplified playground data doesn't fully link Orders effectively without more setup, let's use a conceptual example or a different data set.

For now, let's find Customers from countries where we also have suppliers (assuming we had a suppliers table). Since we don't, let's try finding customers who are in the same country as 'Alfreds Futterkiste'.

SQL PLAYGROUND
⏳ Loading editor…