SQL • LESSON 13
Subqueries
Learn how to use a subquery to compare values against calculated results.
🟡 Intermediate⏱ 2 Minutes⭐ 230 XP
🤔 THE QUESTION
How can we find employees whose salary is higher than the average salary?
💡 WHAT IS IT?
A subquery is a query nested inside another SQL query. The inner query produces a value or result that the outer query can use.
🎯 WHAT IS IT USED FOR?
Subqueries are useful when one query depends on the result of another query, such as comparing rows against an average, maximum, minimum, or another calculated value.
💻 EXAMPLE
SELECT name,
salary
FROM employees
WHERE salary > (
SELECT AVG(salary)
FROM employees
);Mission Brief
Practice using a subquery to find employees whose salary is greater than the average salary.
Objectives
- ✓ SELECT
- ✓ FROM
- ✓ Subquery
- ✓ AVG
- ✓ WHERE