SQL FIRST() and LAST() Functions

SQL FIRST() Function

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

Syntax:
SELECT FIRST(Column_name) FROM table_name;
OR
SELECT FIRST(Column_name) AS First_Name FROM table_name;

Example : Query using FIRST() Function
Consider the following table titled as 'Stationary', which contains the information of products.

Write a query to display a first name from table 'Stationary'.

IDNameQuantityPrice
1Pen10200
2Ink15300
3Notebook20400
4Pencil30150

SELECT FIRST(Name) AS First_name FROM Stationary;

The result is shown in the following table.

First_name
Pen

Note: The FIRST() function is only supported in MS Access.

SQL LAST() Function

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

Syntax:
SELECT LAST(Column_name) FROM table_name;
OR
SELECT LAST(Column_name) AS Last_Name FROM table_name;

Example : Query using LAST() Function.
Consider the following table titled as 'Stationary', which contains the information of products.

Write a query to display a last name from table 'Stationary'.

IDNameQuantityPrice
1Pen10200
2Ink15300
3Notebook20400
4Pencil30150

SELECT Last(Name) AS Last_name FROM Stationary;

The result is shown in the following table.

Last_name
Pencil

Note: The LAST() function is only supported in MS Access.