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

  • email
  • Add to favorites
  • Facebook
  • Twitter
  • MySpace
  • del.icio.us
  • LinkedIn
  • Digg
  • StumbleUpon
  • Google Bookmarks
  • Yahoo! Buzz
  • IndianPad
  1. No comments yet.
(will not be published)

  1. No trackbacks yet.