SQL SELECT LAST

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

SQL SELECT LAST Syntax

Let’s check the syntax of the SQL SELECT LAST() function:

SELECT LAST(column_name) FROM table_name;

In this syntax,

  1. The function LAST() takes column_name as a parameter.
  2. column_name – The name of the column from which you want to check the last value.
  3. table_name – The name of the table from which you want to check the data.

Note that the last() function is only supported by MS Access. This function does not work with other database like Microsoft SQL Server, Oracle or MySQL.

SQL SELECT FIRST Example

We will consider below Employee table for our reference and example.

emp_id emp_name emp_gender dept_code emp_location
1510 Avinash Sirsath M 101 Mumbai
1511 Ramjan Ali M 105 Kolkata
1512 Piyanka Saha F 103 Kolkata
1513 Piyam mondal M 101 Kolkata
1514 Jitu Garg M 104 Mumbai
1515 Raman Sahani M 105 Delhi
1516 Lata Malhotra F 104 Mumbai
1517 Prakash Javedkar M 101 Delhi
1518 Nitu Rani F 103 Mumbai
1519 Pallab Das M 103 Kolkata
1520 Pankaj Sharma M 101 Bangalore

To get the last employee name from the Employee table, you can write the below query.

SELECT LAST(emp_name) AS LAST_Employee FROM Employee;

Once the above query executed, it will show the below result.

Pankaj Sharma

Summary: In this tutorial, you have learned about the SQL SELECT LAST() function. Note that this is only work with MS Access Database.