How to select the Last row from a MySQL table

You can use the following command to get the last row from a MySQL table:

SELECT * FROM table ORDER BY field DESC LIMIT 1

Explanation:

table – table name

field – table field

This command orders the table by DESCENDING order and limits the number of rows returned to 1. Since DESCENDING reverses the normal table order, we get its last row.

Example:

SELECT * FROM tusers ORDER BY user_id DESC LIMIT 1

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.