SQL SELECT LAST

The SQL SELECT LAST statement is used to retrieve the last record from the table. This can be helpful if you want to see the most recent entry added to a table.

Syntax

The basic syntax for SELECT LAST is:

SELECT LAST column_name
FROM table_name;
        

Example

We will now retrieve the last product ordered in the Orders table.

Code Example


-- Select the last product ordered
SELECT LAST Product FROM Orders;
            

Output

Tablet

Explanation

- The query retrieves the last product ordered in the Orders table.
- The result will be based on the order in which the data was inserted into the table.