tags:

views:

52

answers:

2

i am running mysql and i would like to display the last 10 records that were added. what is the select statement for this?

+1  A: 

If you have an autoincrementing ID you can use this:

SELECT *
FROM yourtable
ORDER BY id DESC
LIMIT 10

If you have a column added_datetime that is set to the time of the insert then you can use that instead:

SELECT *
FROM yourtable
ORDER BY added_datetime DESC
LIMIT 10
Mark Byers
+2  A: 

If you have an auto-incrementing ID, you can do this:

SELECT * FROM my_table ORDER BY id DESC LIMIT 10;

If you don't, you'll need some criteria you can order by. An insertion date or something. The LIMIT 10 clause is what you're looking for here.

Samir Talwar