MySQL last function is used to return the last value of the selected column.
Syntax:
SELECT column_name
FROM table_name
ORDER BY column_name DESC
LIMIT 1;
MySQL last function example
Consider a table “officers” having the following data.
Execute the following query:
SELECT officer_name
FROM officers
ORDER BY officer_id DESC
LIMIT 1;
This query will return the last officer_name ordering by officer_id.
Output:
Return the last officer_name ordering by officer_name:
SELECT officer_name
FROM officers
ORDER BY officer_name DESC
LIMIT 1;
Output:
Leave a Reply