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.

Practice it on a real question

All Subqueries questions

Practice on your iPhone

Query Dojo for iPhone has 85 interview questions, timed mock interviews and a tile builder, so you can write queries without a keyboard.

Get the app