BeginnerCoder

Lesson 15 — Subqueries

Subqueries: a query inside a query

A subquery is a SELECT in brackets used inside another query. A subquery that returns one value can be compared like a number. "Products more expensive than average" needs the average first — the subquery computes it, the outer query uses it.

SELECT name FROM products
WHERE price > (SELECT AVG(price) FROM products)

Why it matters: subqueries let you answer two-step questions in one query, without copying numbers by hand.

Want it another way?
Task

Replace the hard-coded 0 with a subquery that computes the average price. Expected: Lamp and Chair (average is 30).

Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.

← Back
Next →
Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.