FIRST VALUE function in SQL Server

FIRST VALUE function in SQL Server

In this video we will discuss FIRST_VALUE function in SQL Server

FIRST_VALUE function
Introduced in SQL Server 2012
Retrieves the first value from the specified column
ORDER BY clause is required
PARTITION BY clause is optional

Syntax : FIRST_VALUE(Column_Name) OVER (ORDER BY Col1, Col2, …)

FIRST_VALUE function example WITHOUT partitions : In the following example, FIRST_VALUE function returns the name of the lowest paid employee from the entire table.

SELECT Name, Gender, Salary,
FIRST_VALUE(Name) OVER (ORDER BY Salary) AS FirstValue
FROM Employees

FIRST_VALUE function example WITH partitions : In the following example, FIRST_VALUE function returns the name of the lowest paid employee from the respective partition.

SELECT Name, Gender, Salary,
FIRST_VALUE(Name) OVER (PARTITION BY Gender ORDER BY Salary) AS FirstValue
FROM Employees

Text version of the video
http://csharp-video-tutorials.blogspot.com/2015/10/firstvalue-function-in-sql-server.html

Slides
http://csharp-video-tutorials.blogspot.com/2015/10/firstvalue-function-in-sql-server_6.html

All SQL Server Text Articles
http://csharp-video-tutorials.blogspot.com/p/free-sql-server-video-tutorials-for.html

All SQL Server Slides
http://csharp-video-tutorials.blogspot.com/p/sql-server.html

All Dot Net and SQL Server Tutorials in English
https://www.youtube.com/user/kudvenkat/playlists?view=1&sort=dd

All Dot Net and SQL Server Tutorials in Arabic
https://www.youtube.com/c/KudvenkatArabic/playlists

Get Paid Taking Pictures
Share