MySQL last function

MySQL last function is used to return the last value of the selected column.

Syntax:

snippet
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.

mysql last() 1

Execute the following query:

snippet
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:

mysql last() 2

Return the last officer_name ordering by officer_name:

snippet
SELECT officer_name 
FROM officers
ORDER BY officer_name DESC
LIMIT 1;

Output:

mysql last() 3
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents