SQL LAST() Function
- Previous Page SQL first()
- Next Page SQL max()
LAST() Function
The LAST() function returns the value of the last record in the specified field.
Tip:You can use the ORDER BY statement to sort the records.
SQL LAST() Syntax
SELECT LAST(column_name) FROM table_name
SQL LAST() Example
We have the following "Orders" table:
O_Id | OrderDate | OrderPrice | Customer |
---|---|---|---|
1 | 2008/12/29 | 1000 | Bush |
2 | 2008/11/23 | 1600 | Carter |
3 | 2008/10/05 | 700 | Bush |
4 | 2008/09/28 | 300 | Bush |
5 | 2008/08/06 | 2000 | Adams |
6 | 2008/07/21 | 100 | Carter |
Now, we want to find the last value in the "OrderPrice" column.
We use the following SQL statement:
SELECT LAST(OrderPrice) AS LastOrderPrice FROM Orders
The result set is similar to this:
LastOrderPrice |
---|
100 |
- Previous Page SQL first()
- Next Page SQL max()