MySQL last() function

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

Syntax:

  1. SELECT column_name
  2. FROM table_name
  3. ORDER BY column_name DESC
  4. LIMIT 1;

MySQL last function example

Consider a table “officers” having the following data.

mysql last() 1

Execute the following query:

  1. SELECT officer_name
  2. FROM officers
  3. ORDER BY officer_id DESC
  4. 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:

  1. SELECT officer_name
  2. FROM officers
  3. ORDER BY officer_name DESC
  4. LIMIT 1;

Output:

mysql last() 3

Spread the love

Leave a Reply

Your email address will not be published. Required fields are marked *