Skip to main content
SQL โ€ข LESSON 159

First Value

How can we display the department's top salary on every employee's record?

Advancedโฑ 3 Minutesโญ 1720 XP
๐Ÿค” THE QUESTION

How can we display the department's top salary on every employee's record?

๐Ÿ’ก WHAT IS IT?

FIRST_VALUE(column) retrieves the value from the initial row of the window frame.

๐ŸŽฏ WHAT IS IT USED FOR?

Benchmarking employees against the department highest earner, baseline comparisons.

๐Ÿ’ป EXAMPLE
SELECT
department_id,
name,
salary,
FIRST_VALUE(salary) OVER (
    PARTITION BY department_id
    ORDER BY salary DESC
) AS highest_salary
FROM employees;

๐ŸŽฏ Mission Objectives

Practice typing production-grade SQL code for First Value.

  • โœ“ FIRST_VALUE()
  • โœ“ Top boundary lookup
  • โœ“ Partition maximum reference
  • โœ“ Comparative reporting