SQL LAST() Function

The LAST() function returns the last value of the selected column.
SQL LAST() Syntax
SELECT LAST(column_name) FROM table_name
SQL LAST() Example
We have the following "Orders" table:
O_IdOrderDateOrderPriceCustomer
12008/11/121000Hansen
22008/10/231600Nilsen
32008/09/02700Hansen
42008/09/03300Hansen
52008/08/302000Jensen
62008/10/04100Nilsen

Now we want to find the last value of the "OrderPrice" column.
We use the following SQL statement:
SELECT LAST(OrderPrice) AS LastOrderPrice FROM Orders
  • Tip: Workaround if LAST() function is not supported:
SELECT OrderPrice FROM Orders ORDER BY O_Id DESC LIMIT 1
The result-set will look like this:
LastOrderPrice
100

No comments: