FIRST_VALUE()
FIRST_VALUE() is a SQL function in the Window Functions category. Returns the first value in an ordered window frame. Useful for comparisons with the first row. The syntax is FIRST_VALUE(column) OVER (PARTITION BY col ORDER BY col). It accepts column. It returns first value in frame. A typical example: SELECT name, salary, FIRST_VALUE(name) OVER (ORDER BY salary DESC) AS highest_paid FROM employees; -- Every row shows the name of the highest paid employee A close relative is ROW_NUMBER(), which assigns a unique sequential integer to each row within its partition (1, 2, 3...). A close relative is RANK(), which similar to ROW_NUMBER but gives the same rank to equal values. Leaves gaps in ranking. A close relative is DENSE_RANK(), which like RANK but without gaps. Equal values get the same rank, and the next number follows sequentially. More about this category: Window/analytical functions — ROW_NUMBER, RANK, DENSE_RANK, LAG, LEAD, NTILE.