last function

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.

    mysql last() 1

    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:

      mysql last() 2

      Return the last officer_name ordering by officer_name:

      SELECT officer_name   
      
      FROM officers  
      
      ORDER BY officer_name DESC  
      
      LIMIT 1;  

        Output:

        mysql last() 3

        Comments

        Leave a Reply

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