Interactive SQL practice

SQL Subquery Exercises

Practice nested queries and compare values against calculated result sets. These 2 interactive challenges use real schemas and instant query validation.

2 SQL challenges

Open Practice Arena
Subqueries
Intermediate

Orders Above Average Value

Find orders whose total amount is greater than the average order value. Return columns: id, customer_id, total_amount. Order results by: total_amount DESC.

Concept guide

How to practice SQL Subquery

A SQL subquery is a query nested inside another statement. It can return a scalar value, a list of values, or a derived table used by the outer query.

What to master

  • • Distinguish scalar, list and table subqueries
  • • Use correlated subqueries only when row-by-row logic is intended
  • • Consider EXISTS for existence checks
  • • Compare subquery and JOIN plans for clarity and performance

A reliable problem-solving workflow

  1. 1Solve the inner calculation independently.
  2. 2Confirm its result shape: one value, many values or a table.
  3. 3Place it in WHERE, SELECT or FROM as appropriate.
  4. 4Run the complete query and check NULL behavior.
When should I use EXISTS instead of IN?

EXISTS is a natural choice when you only need to know whether a matching row exists. Always consider NULL behavior when using IN or NOT IN.

Are subqueries slower than JOINs?

Not automatically. Modern optimizers can transform both forms. Choose the clearest correct query, then inspect the execution plan for performance-sensitive work.