intermediate

FIRST_VALUE

5 min readLast updated: 2026-07-23

Overview

FIRST_VALUE() returns the first value in an ordered window frame or partition.

Learning Objectives

  • Retrieve initial boundary values using FIRST_VALUE().
  • Compare current row values against baseline partition starting points.

Detailed Concept Explanation

FIRST_VALUE(column) OVER (PARTITION BY ... ORDER BY ...) returns the value of column from the first row in the window frame.


Code Examples

SQL

sql
-- Compare each employee's salary to the HIGHEST salary in their department
SELECT 
    name,
    department_id,
    salary,
    FIRST_VALUE(salary) OVER (
        PARTITION BY department_id 
        ORDER BY salary DESC
    ) AS top_dept_salary
FROM employees;

Summary

FIRST_VALUE() returns the first record value in an ordered window frame.