Intermediate · Lesson 7 of 20

Introduction to Subqueries

A subquery is a query inside another query.

Find employees earning more than average:

SELECT * FROM employees
WHERE salary > (SELECT AVG(salary) FROM employees);

The inner query runs first, returns a value, then the outer query uses it.

Subqueries can appear in:

  • WHERE clause (most common)
  • FROM clause
  • SELECT clause
Check your understanding

Find employees earning more than the average salary.

Examples run on the employees sample database. Open any of them in the playground to experiment.