somejkuser
somejkuser

Reputation: 9040

SQL Retrieving the last record in a sql query

I need to retrieve the last record in a mysql database table - is there a command for this?

Upvotes: 1

Views: 170

Answers (2)

Mark Byers
Mark Byers

Reputation: 837966

Assuming you want the row with the largest auto-incrementing id, you can do this.

SELECT * FROM Table1 ORDER BY id DESC LIMIT 1

Upvotes: 1

ChssPly76
ChssPly76

Reputation: 100696

Last by what order?

SELECT * FROM my_table ORDER BY something (DESC) LIMIT 1

Upvotes: 3

Related Questions