开发者

how do i select the last 10 records added?

i am running mysql and i would like to display the last 10 records that were added. 开发者_运维知识库what is the select statement for this?


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.


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜