Skip to main content
SQL โ€ข LESSON 93

Scalar Subquery

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

Advancedโฑ 3 Minutesโญ 1060 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