Skip to main content
SQL • LESSON 93

Scalar Subquery

How can we find employees earning more than the company average?

Advanced3 Minutes1060 XP
🤔 THE QUESTION

How can we find employees earning more than the company average?

💡 WHAT IS IT?

A scalar subquery returns a single value that can be used directly in comparison operators (> , < , =).

🎯 WHAT IS IT USED FOR?

Benchmarking individual rows against global averages, dynamic threshold comparisons.

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

🎯 Mission Objectives

Practice typing production-grade SQL code for Scalar Subquery.

  • Scalar subquery
  • AVG subquery comparison
  • Dynamic thresholds
  • Nested SELECT