SQLancer
LESSON 19

SQL (Core) - Subqueries & Nested Queries

Progress: 0%

SQL Lesson 19: Subqueries & Nested Queries

A subquery (or nested query) is an inner SQL SELECT statement embedded inside an outer query's WHERE, FROM, or HAVING clause.

Using Subqueries in WHERE Conditions

Subqueries allow dynamic filtering against calculated baseline statistics (like average sales or max values) without hardcoding magic numbers:

SELECT title FROM movies
WHERE domestic_sales > (
SELECT AVG(domestic_sales) FROM boxoffice
);

🗄️ Schema Explorer SELECTABLE

movies
|

🎯 Exercises Checklist:

1. Find all movies whose domestic sales are greater than the average domestic sales of all movies
2. Select employee names whose building capacity is greater than 30 using a subquery
⚡ Practice Console

Data Output

No results. Run query to fetch data.

Current Task Target

5 rows