Skip to main content
SQL • LESSON 13

SQL Subqueries

How can we filter records using a dynamically computed value from another query?

Intermediate2 Minutes230 XP
🤔 THE QUESTION

How can we filter records using a dynamically computed value from another query?

💡 WHAT IS IT?

A scalar subquery is a nested query enclosed in parentheses that computes an intermediate value.

🎯 WHAT IS IT USED FOR?

Finding records above average, comparing against dynamic thresholds, multi-tier data lookup.

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

🎯 Mission Objectives

Practice typing production-grade SQL code for SQL Subqueries.

  • Scalar Subquery
  • Nested SELECT
  • Dynamic thresholds
  • AVG() in subquery