SQL FIRST() & LAST() Function


The FIRST() Function

The FIRST() function returns the first value of the selected column.

Syntax

SELECT FIRST(column_name) FROM table_name;

Example

student Table

stud_sidstud_namestud_fee
11211Ashwani400
11212Sachin200
11213Deepak600
11214Sanjay800
SELECT FIRST(stud_fee) FROM student;
Output
400

The LAST() Function

The LAST() function returns the last value of the selected column.

Syntax
SELECT LAST(column_name) FROM table_name;

Example

student Table

stud_sidstud_namestud_fee
11211Ashwani400
11212Sachin200
11213Deepak800
11214Sanjay900
SELECT LAST(stud_fee) FROM student;
Output
900

Share this article on