The LAST() Function
The LAST() function returns the last value of the selected column.
SQL LAST() Syntax
SELECT LAST(column_name) FROM table_name;
Note: The LAST() function is only supported in MS Access.
SQL LAST() Workaround in SQL Server, MySQL and Oracle
SQL Server Syntax
SELECT TOP 1 column_name FROM table_name
ORDER BY column_name DESC;
ORDER BY column_name DESC;
Example
SELECT TOP 1 CustomerName FROM Customers
ORDER BY CustomerID DESC;
ORDER BY CustomerID DESC;
MySQL Syntax
SELECT column_name FROM table_name
ORDER BY column_name DESC
LIMIT 1;
ORDER BY column_name DESC
LIMIT 1;
Example
SELECT CustomerName FROM Customers
ORDER BY CustomerID DESC
LIMIT 1;
ORDER BY CustomerID DESC
LIMIT 1;
Oracle Syntax
SELECT column_name FROM table_name
ORDER BY column_name DESC
WHERE ROWNUM <=1;
ORDER BY column_name DESC
WHERE ROWNUM <=1;
Example
SELECT CustomerName FROM Customers
ORDER BY CustomerID DESC
WHERE ROWNUM <=1;
ORDER BY CustomerID DESC
WHERE ROWNUM <=1;