Summary - Subquery
- SQL course
- Intermediate
- Lesson 52/115
- 5 min
Find rows above the average with IN and scalar subqueries.
Summary - Subquery
A subquery sits inside another query. Types include scalar, IN and correlated.
SELECT name FROM products
WHERE price > (SELECT AVG(price) FROM products);Summary subquery.
name is selected from products. WHERE keeps only the rows where price > (SELECT AVG(price) FROM products) holds.
Practice Summary - Subquery
Summary: find products above average with a subquery.
Starter code
-- summary subquery
SELECT name FROM products
WHERE price >Sample solution
SELECT name FROM products
WHERE price > (SELECT AVG(price) FROM products);Expected output
name Laptop Telefon
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which subquery returns a single value?
- IN
- EXISTS
- A scalar subquery Correct answer
- A correlated subquery
Explanation: A scalar subquery returns a single value.
2 Summary - Subquery: match the terms
| Term | Meaning |
|---|---|
scalar |
single value |
IN |
list |
correlated |
outer-dependent |
ANY |
any |