Section 1 - Instruction

Welcome to subqueries! These are queries inside other queries - like nesting one SELECT statement inside another. Think of them as asking SQL to "first find this, then use that result to find something else."

Engagement Message

When might you need to find data based on results from another query?

Section 2 - Instruction

A subquery always goes inside parentheses and typically appears in the WHERE clause. The inner query runs first, returns results, then the outer query uses those results.

Engagement Message

Which part runs first—inner SELECT or outer SELECT?

Section 3 - Instruction

Let's break down that example. The subquery (SELECT customer_id FROM orders) finds all customer IDs who have placed orders. Then the main query finds names for those customers.

This gives you customers who have actually ordered something.

Engagement Message

Why might finding "customers with orders" be useful for a business?

Section 4 - Instruction

Here's another practical example. Find products that cost more than the average price:

The subquery calculates the average first, then the main query finds products above that average.

Engagement Message

What does the subquery (SELECT AVG(price) FROM products) return?

Section 5 - Instruction

Subqueries can also appear in FROM clauses, creating temporary result sets. This treats the subquery results like a table:

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal